Skip to content

Commit

Permalink
feat: improve inline suggestion(ghost text)
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 5, 2024
1 parent 03071fa commit e65cbaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"registry": "https://registry.npmjs.org"
},
"license": "MIT",
"version": "2.4.1",
"version": "2.5.0",
"packageManager": "pnpm@9.0.6",
"scripts": {
"update:config": " pnpm ts-node scripts/generateConfig.ts",
Expand Down
19 changes: 15 additions & 4 deletions src/tiddlywiki-codemirror-6/modules/extensions/inlinesuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { inlineSuggestion } from '@/cm6/modules/extensions/inlineSuggestion';
import { completionStatus, selectedCompletion } from '@codemirror/autocomplete';
import cm6 from '@/cm6/config';
import { EditorView } from '@codemirror/view';
import { delimiters } from '../completions/sources';

// @WIP
// @see-also: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/ui/components/text_editor/config.ts#L370
Expand All @@ -16,6 +17,7 @@ export default function inlineSuggestionExt(self: {
// TODO: how to refresh
// status wrong
const fetchSuggestion = () => {
console.log('inlineSuggestion ...');
const state = self.editor.state;
const status = completionStatus(state) === 'active';
if (!status) {
Expand All @@ -42,11 +44,20 @@ export default function inlineSuggestionExt(self: {
return;
}

// 如果不开启 show completion, 就获取不到列表
// @NOTE: 如果不开启 show completion, 就获取不到列表
if (status) {
// TODO: 需要细化逻辑
// return selectedCompletion(state)?.label.slice(0, lastWord.length);
return ' ' + selectedCompletion(state)?.displayLabel;
const completion = selectedCompletion(state);
if (
completion?.label?.toString().startsWith(lastWord) ||
completion?.displayLabel?.toString().startsWith(lastWord)
) {
return (
completion?.label.slice(lastWord.length) ||
completion?.displayLabel?.slice(lastWord.length)
);
} else {
return ' ' + (completion?.label || completion?.displayLabel);
}
}
return '';
};
Expand Down
2 changes: 1 addition & 1 deletion src/tiddlywiki-codemirror-6/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "$:/plugins/oeyoews/tiddlywiki-codemirror-6",
"name": "CodeMirror6",
"description": "CodeMirror 6 editor",
"version": "2.4.1",
"version": "2.5.0",
"core-version": ">=5.3.4",
"list": "readme usage"
}

0 comments on commit e65cbaf

Please sign in to comment.