Add Lexical-based composer editor with file mention pills #142
Mergedjuliusmarmingemerged 3 commits into
main fromt3code/file-mention-pills-textareamerged by juliusmarminge View on GitHub- apps/web/src/components/ChatView.tsx line 2125OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2058,15 +2113,13 @@20582113 nudgeComposerMenuHighlight("ArrowDown");2059- return;2114+ return true;20602115 }2061- if (e.key === "ArrowUp") {2062- e.preventDefault();2116+ if (key === "ArrowUp" && currentItems.length > 0) {20632117 nudgeComposerMenuHighlight("ArrowUp");2064- return;2118+ return true;20652119 }2066- if (e.key === "Tab" || e.key === "Enter") {2067- const selectedItem = activeComposerMenuItem ?? composerMenuItems[0];2120+ if (key === "Tab" || key === "Enter") {2121+ const selectedItem = activeComposerMenuItemRef.current ?? currentItems[0];20682122 if (selectedItem) {2069- e.preventDefault();20702123 onSelectComposerItem(selectedItem);2071- return;20722124 }2125+ return true;apps/web/src/components/ComposerPromptEditor.tsx line 155OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +135,21 @@135+136+function inferMentionPathKind(pathValue: string): "file" | "directory" {137+ const base = basenameOfPath(pathValue);138+ if (base.startsWith(".") && !base.slice(1).includes(".")) {139+ return "directory";140+ }141+ if (base.includes(".")) {142+ return "file";143+ }144+ return "directory";145+}146+147+function renderMentionChipDom(container: HTMLElement, pathValue: string): void {148+ container.textContent = "";149+150+ const icon = document.createElement("img");151+ icon.alt = "";152+ icon.ariaHidden = "true";153+ icon.className = "size-3.5 shrink-0 opacity-85";154+ icon.loading = "lazy";155+ icon.src = getVscodeIconUrlForEntry(pathValue, inferMentionPathKind(pathValue), "dark");
- @@ -0,0 +452,21 @@452+ COMMAND_PRIORITY_HIGH,453+ );454+455+ return () => {456+ unregisterArrowDown();457+ unregisterArrowUp();458+ unregisterEnter();459+ unregisterTab();460+ };461+ }, [editor, props]);462+463+ return null;464+}465+466+function ComposerMentionArrowPlugin() {467+ const [editor] = useLexicalComposerContext();468+469+ useEffect(() => {470+ const unregisterLeft = editor.registerCommand(471+ KEY_ARROW_LEFT_COMMAND,472+ () => {
- apps/web/src/components/ChatView.tsx line 2205Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1998,9 +1999,16 @@1999+ const currentText = promptRef.current;2000+ const safeStart = Math.max(0, Math.min(currentText.length, rangeStart));2001+ const safeEnd = Math.max(safeStart, Math.min(currentText.length, rangeEnd));2002+ if (2003+ options?.expectedText !== undefined &&2004+ currentText.slice(safeStart, safeEnd) !== options.expectedText2005+ ) {2006+ return false;2007+ }19982008 const next = replaceTextRange(promptRef.current, rangeStart, rangeEnd, replacement);19992009 promptRef.current = next.text;20002010 setPrompt(next.text);2011+ setComposerCursor(next.cursor);2012+ setComposerTrigger(detectComposerTrigger(next.text, next.cursor));20012013 window.requestAnimationFrame(() => {2002- const textarea = textareaRef.current;2003- if (!textarea) return;2004- textarea.focus();2005- textarea.setSelectionRange(next.cursor, next.cursor);2006- setComposerCursor(next.cursor);2014+ composerEditorRef.current?.focusAt(next.cursor);
juliusmarminge merged this5e78386
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.