Skip to content

Commit b87a4ab

Browse files
committed
initial autocomplete attempt
1 parent d192b37 commit b87a4ab

File tree

5 files changed

+456
-7
lines changed

5 files changed

+456
-7
lines changed

examples/09-ai/01-minimal/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import {
1515
AIMenuController,
1616
AIToolbarButton,
17+
createAIAutoCompleteExtension,
1718
createAIExtension,
1819
getAISlashMenuItems,
1920
} from "@blocknote/xl-ai";
@@ -41,6 +42,7 @@ export default function App() {
4142
api: `${BASE_URL}/regular/streamText`,
4243
}),
4344
}),
45+
createAIAutoCompleteExtension(),
4446
],
4547
// We set some initial content for demo purposes
4648
initialContent: [

packages/core/src/extensions/SuggestionMenu/SuggestionPlugin.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class SuggestionMenuProseMirrorPlugin<
290290
},
291291

292292
props: {
293-
handleTextInput(view, from, to, text) {
293+
handleTextInput(view, from, to, text, deflt) {
294294
// only on insert
295295
if (from === to) {
296296
const doc = view.state.doc;
@@ -301,18 +301,21 @@ export class SuggestionMenuProseMirrorPlugin<
301301
: text;
302302

303303
if (str === snippet) {
304-
view.dispatch(view.state.tr.insertText(text));
305304
view.dispatch(
306-
view.state.tr
307-
.setMeta(suggestionMenuPluginKey, {
308-
triggerCharacter: snippet,
309-
})
310-
.scrollIntoView(),
305+
deflt().setMeta(suggestionMenuPluginKey, {
306+
triggerCharacter: snippet,
307+
}),
311308
);
312309
return true;
313310
}
314311
}
315312
}
313+
if (this.getState(view.state)) {
314+
// when menu is open, we dispatch the default transaction
315+
// and return true so that other event handlers (i.e.: AI AutoComplete) are not triggered
316+
view.dispatch(deflt());
317+
return true;
318+
}
316319
return false;
317320
},
318321

packages/xl-ai/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export * from "./components/AIMenu/PromptSuggestionMenu.js";
1111
export * from "./components/FormattingToolbar/AIToolbarButton.js";
1212
export * from "./components/SuggestionMenu/getAISlashMenuItems.js";
1313
export * from "./i18n/dictionary.js";
14+
export * from "./plugins/AutoCompletePlugin.js";
1415
export * from "./streamTool/index.js";

0 commit comments

Comments
 (0)