Skip to content

Commit

Permalink
chore: bind note title to window
Browse files Browse the repository at this point in the history
  • Loading branch information
anig1scur committed Oct 23, 2024
1 parent fbe8af5 commit 4506070
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ export class Note extends GObject.Object {
"title",
GObject.BindingFlags.SYNC_CREATE,
(_, content) => {
if (!content) return [false, ""];

const title = content.split("\n")[0];
return [true, title.length > 20 ? title.slice(0, 20) + "..." : title];
if (!content) return [true, ""];
let title = content.split("\n")[0].slice(0, 20);
if (title.length != content.length) title += "…";
return [true, title];
},
null
);
Expand Down
19 changes: 6 additions & 13 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ export class Window extends Adw.ApplicationWindow {
this.default_width = note.width;
this.default_height = note.height;

this.update_title();

this.note.connect("notify::title", () => {
this.update_title();
});
this.note.bind_property(
"title",
this,
"title",
GObject.BindingFlags.SYNC_CREATE
);

this.connect("close-request", () => {
if (this.deleted) return;
Expand Down Expand Up @@ -157,14 +158,6 @@ export class Window extends Adw.ApplicationWindow {
popover.add_child(this.selector, "notestyleswitcher");
}

update_title() {
if (!this.note.title) {
this.set_title("Untitled Note");
return;
}
this.set_title(this.note.title);
}

last_revealer = false;

update_link(selected: boolean, text: string) {
Expand Down

0 comments on commit 4506070

Please sign in to comment.