Skip to content

Commit

Permalink
Merge pull request #13 from socketteer/fixes+prepend
Browse files Browse the repository at this point in the history
Fixes+prepend
  • Loading branch information
cosmicoptima authored Nov 7, 2023
2 parents beafcdd + 4b0c9eb commit 8dfa97a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface LoomSettings {
topP: number;
frequencyPenalty: number;
presencePenalty: number;
prepend: string;
bestOf: number;
n: number;

Expand Down
53 changes: 35 additions & 18 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DEFAULT_SETTINGS: LoomSettings = {
topP: 1,
frequencyPenalty: 0,
presencePenalty: 0,
prepend: "<|endoftext|>",
bestOf: 0,
n: 5,

Expand Down Expand Up @@ -700,24 +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 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);
// 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;

// // 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);
})
)
);
Expand Down Expand Up @@ -1154,7 +1169,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);
}

Expand All @@ -1174,7 +1191,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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8dfa97a

Please sign in to comment.