From a5c4ea653bbc7558f248d4974dae20b85351379c Mon Sep 17 00:00:00 2001 From: socketteer Date: Mon, 6 Nov 2023 16:01:55 -0500 Subject: [PATCH 1/5] add prepend sequence setting and scroll active tree node into view --- views.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/views.ts b/views.ts index 6c1dbd4..21880d1 100644 --- a/views.ts +++ b/views.ts @@ -146,6 +146,12 @@ export class LoomView extends ItemView { this.renderTree(this.tree, state); this.containerEl.scrollTop = scroll; + + // scroll to active node in the tree + const activeNode = this.tree.querySelector(".is-active"); + if (activeNode){ //&& !container.contains(activeNode)){ + activeNode.scrollIntoView({ block: "nearest" }); + } } renderNavButtons(settings: LoomSettings) { @@ -327,6 +333,7 @@ export class LoomView extends ItemView { setting("Top p", "topP", String(settings.topP), "float"); setting("Frequency penalty", "frequencyPenalty", String(settings.frequencyPenalty), "float"); setting("Presence penalty", "presencePenalty", String(settings.presencePenalty), "float"); + setting("Prepend sequence", "prepend", settings.prepend, "string"); } renderBookmarks(container: HTMLElement, state: NoteState) { From 774464ffd3db37f4fb6775b9f141fec9b5075b40 Mon Sep 17 00:00:00 2001 From: socketteer Date: Mon, 6 Nov 2023 16:02:16 -0500 Subject: [PATCH 2/5] add prepend setting --- common.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/common.ts b/common.ts index 7874fb3..f2cba54 100644 --- a/common.ts +++ b/common.ts @@ -26,6 +26,7 @@ export interface LoomSettings { topP: number; frequencyPenalty: number; presencePenalty: number; + prepend: string; bestOf: number; n: number; From 98e7c69401ad771c3d7a0e4182aa5e8552f4dab8 Mon Sep 17 00:00:00 2001 From: socketteer Date: Mon, 6 Nov 2023 16:03:22 -0500 Subject: [PATCH 3/5] add prepend setting, select parent node after splitting before generating, fix editor scroll to top issue --- main.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/main.ts b/main.ts index d9c05d0..5beae6a 100644 --- a/main.ts +++ b/main.ts @@ -73,6 +73,7 @@ const DEFAULT_SETTINGS: LoomSettings = { topP: 1, frequencyPenalty: 0, presencePenalty: 0, + prepend: "<|endoftext|>", bestOf: 0, n: 5, @@ -704,6 +705,14 @@ export default class LoomPlugin extends Plugin { const linesBefore = this.editor.getValue().split("\n"); this.editor.setValue(this.fullText(file, id)); + // if the cursor is at the beginning of the editor, move it to the end + if(cursor.line === 0 && cursor.ch === 0) { + const line = this.editor.lineCount() - 1; + const ch = this.editor.getLine(line).length; + this.editor.setCursor({ line, ch }); + return; + } + // if the text preceding the cursor has changed, move the cursor to the end of the text // otherwise, restore the cursor position const linesAfter = this.editor @@ -712,10 +721,10 @@ export default class LoomPlugin extends Plugin { .slice(0, cursor.line + 1); for (let i = 0; i < cursor.line; i++) if (linesBefore[i] !== linesAfter[i]) { - const line = this.editor.lineCount() - 1; - const ch = this.editor.getLine(line).length; - this.editor.setCursor({ line, ch }); - return; + const line = this.editor.lineCount() - 1; + const ch = this.editor.getLine(line).length; + this.editor.setCursor({ line, ch }); + return; } this.editor.setCursor(cursor); }) @@ -1154,7 +1163,9 @@ export default class LoomPlugin extends Plugin { async complete(file: TFile) { const state = this.state[file.path]; - this.breakAtPoint(file); + const [parentNode] = this.breakAtPoint(file); + // switch to the parent node + this.app.workspace.trigger("loom:switch-to", parentNode); await this.generate(file, state.current); } @@ -1174,7 +1185,7 @@ export default class LoomPlugin extends Plugin { // show the "Generating..." indicator in the loom view this.renderLoomViews(); - let prompt = `<|endoftext|>${this.fullText(file, rootNode)}`; + let prompt = `${this.settings.prepend}${this.fullText(file, rootNode)}`; // remove a trailing space if there is one // store whether there was, so it can be added back post-completion From c36dd1320df4334ba83f580c81a2b7549eab94fd Mon Sep 17 00:00:00 2001 From: socketteer Date: Mon, 6 Nov 2023 16:04:34 -0500 Subject: [PATCH 4/5] update version --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c75ad9..4063bf6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-loom", - "version": "1.16.3", + "version": "1.17.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-loom", - "version": "1.16.3", + "version": "1.17.0", "license": "MIT", "dependencies": { "@codemirror/state": "^6.2.0", From 4b0c9eb269a53441de1540d067810bb148553cb5 Mon Sep 17 00:00:00 2001 From: socketteer Date: Mon, 6 Nov 2023 16:12:16 -0500 Subject: [PATCH 5/5] always move cursor to end of editor when switching nodes --- main.ts | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/main.ts b/main.ts index 5beae6a..dd7d153 100644 --- a/main.ts +++ b/main.ts @@ -701,32 +701,38 @@ export default class LoomPlugin extends Plugin { ); // update the editor's text - const cursor = this.editor.getCursor(); - const linesBefore = this.editor.getValue().split("\n"); + // const cursor = this.editor.getCursor(); + // const linesBefore = this.editor.getValue().split("\n"); this.editor.setValue(this.fullText(file, id)); - // if the cursor is at the beginning of the editor, move it to the end - if(cursor.line === 0 && cursor.ch === 0) { + // always move cursor to the end of the editor const line = this.editor.lineCount() - 1; const ch = this.editor.getLine(line).length; this.editor.setCursor({ line, ch }); - return; - } + // return; - // if the text preceding the cursor has changed, move the cursor to the end of the text - // otherwise, restore the cursor position - const linesAfter = this.editor - .getValue() - .split("\n") - .slice(0, cursor.line + 1); - for (let i = 0; i < cursor.line; i++) - if (linesBefore[i] !== linesAfter[i]) { - const line = this.editor.lineCount() - 1; - const ch = this.editor.getLine(line).length; - this.editor.setCursor({ line, ch }); - return; - } - this.editor.setCursor(cursor); + // // if the cursor is at the beginning of the editor, move it to the end + // if(cursor.line === 0 && cursor.ch === 0) { + // const line = this.editor.lineCount() - 1; + // const ch = this.editor.getLine(line).length; + // this.editor.setCursor({ line, ch }); + // return; + // } + + // // if the text preceding the cursor has changed, move the cursor to the end of the text + // // otherwise, restore the cursor position + // const linesAfter = this.editor + // .getValue() + // .split("\n") + // .slice(0, cursor.line + 1); + // for (let i = 0; i < cursor.line; i++) + // if (linesBefore[i] !== linesAfter[i]) { + // const line = this.editor.lineCount() - 1; + // const ch = this.editor.getLine(line).length; + // this.editor.setCursor({ line, ch }); + // return; + // } + // this.editor.setCursor(cursor); }) ) );