Skip to content

fix: fix bug with jumping cursor after finished completion #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions lib/suggestion-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ let quill: any = null;
const editorFocused = ref(false);

let lastText: string | null = null;
let lastKnownCursorIndex: any = null;


function removeCompletionOnBlur() {
Expand Down Expand Up @@ -216,28 +217,40 @@ onMounted(async () => {

quill.on(Quill.events.TEXT_CHANGE, async (delta: any, oldDelta: any, source: string) => {
dbg('🪽 TEXT_CHANGE fired ', delta, oldDelta, source);
const isEmpty = quill.getLength() <= 4;
if(completion.value && isEmpty){
quill.setSelection(1,0,'silent')
}
updaterQueue.add(emitTextUpdate);
startCompletion();
});

quill.on('selection-change', (range: any, oldRange: any, source: string) => {
dbg('🪽 selection changed', range, oldRange, source);
if (range === null) {
// blur event
removeCompletionOnBlur();
editorFocused.value = false;
return;
} else {
editorFocused.value = true;
startCompletion();
}
const text = quill.getText();
// don't allow to select after completion
if (range?.index === text.length) {
dbg('✋ prevent selection after completion');
quill.setSelection(text.length - 1, 0, 'silent');

if (range === null) {
// blur
editorFocused.value = false;
removeCompletionOnBlur();

if (oldRange && typeof oldRange.index === 'number') {
lastKnownCursorIndex = oldRange;
}
});
return;
}

if (!editorFocused.value && lastKnownCursorIndex) {
quill.setSelection(lastKnownCursorIndex.index, lastKnownCursorIndex.length || 0, 'silent');
lastKnownCursorIndex = null;
}

editorFocused.value = true;
startCompletion();
const text = quill.getText();
if (range.index === text.length) {
quill.setSelection(text.length - 1, 0, 'silent');
}
});


// handle right swipe on mobile uding document/window, and console log if swiped in right direction
Expand Down Expand Up @@ -277,7 +290,7 @@ async function startCompletion() {
tmt = setTimeout(async () => {
const currentTmt = tmt;
const cursorPosition = quill.getSelection();
dbg('👇 get pos', cursorPosition.index, cursorPosition.length)
dbg('👇 get pos', cursorPosition.index, cursorPosition.length);
if (cursorPosition.length !== 0) {
// we will not complete if text selected
return;
Expand Down