Skip to content

Commit 4506070

Browse files
committed
chore: bind note title to window
1 parent fbe8af5 commit 4506070

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ export class Note extends GObject.Object {
222222
"title",
223223
GObject.BindingFlags.SYNC_CREATE,
224224
(_, content) => {
225-
if (!content) return [false, ""];
226-
227-
const title = content.split("\n")[0];
228-
return [true, title.length > 20 ? title.slice(0, 20) + "..." : title];
225+
if (!content) return [true, ""];
226+
let title = content.split("\n")[0].slice(0, 20);
227+
if (title.length != content.length) title += "…";
228+
return [true, title];
229229
},
230230
null
231231
);

src/window.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ export class Window extends Adw.ApplicationWindow {
9898
this.default_width = note.width;
9999
this.default_height = note.height;
100100

101-
this.update_title();
102-
103-
this.note.connect("notify::title", () => {
104-
this.update_title();
105-
});
101+
this.note.bind_property(
102+
"title",
103+
this,
104+
"title",
105+
GObject.BindingFlags.SYNC_CREATE
106+
);
106107

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

160-
update_title() {
161-
if (!this.note.title) {
162-
this.set_title("Untitled Note");
163-
return;
164-
}
165-
this.set_title(this.note.title);
166-
}
167-
168161
last_revealer = false;
169162

170163
update_link(selected: boolean, text: string) {

0 commit comments

Comments
 (0)