GeezerVison is showing github.com — fix(web): keep mentions tokenizable at text boundaries and stop paste… · pingdotgg/t3code@718e283
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditor.tsx +19-1Lines changed: 19 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1144,7 +1144,7 @@ function ComposerInlineTokenPastePlugin() { |
1144 | 1144 | if (mentions.length === 0) { |
1145 | 1145 | return false; |
1146 | 1146 | } |
1147 | | - event.preventDefault(); |
| 1147 | + let inserted = false; |
1148 | 1148 | editor.update(() => { |
1149 | 1149 | const selection = $getSelection(); |
1150 | 1150 | if (!$isRangeSelection(selection)) { |
@@ -1163,6 +1163,19 @@ function ComposerInlineTokenPastePlugin() { |
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | }; |
| 1166 | + const firstMention = mentions[0]; |
| 1167 | + if (firstMention && firstMention.start === 0) { |
| 1168 | + const anchorOffset = getExpandedAbsoluteOffsetForPoint( |
| 1169 | + selection.anchor.getNode(), |
| 1170 | + selection.anchor.offset, |
| 1171 | + ); |
| 1172 | + const precedingChar = $getRoot() |
| 1173 | + .getTextContent() |
| 1174 | + .slice(anchorOffset - 1, anchorOffset); |
| 1175 | + if (precedingChar.length > 0 && !/\s/.test(precedingChar)) { |
| 1176 | + nodes.push($createTextNode(" ")); |
| 1177 | + } |
| 1178 | + } |
1166 | 1179 | let cursor = 0; |
1167 | 1180 | for (const mention of mentions) { |
1168 | 1181 | if (mention.start < cursor) { |
@@ -1183,7 +1196,12 @@ function ComposerInlineTokenPastePlugin() { |
1183 | 1196 | nodes.push($createTextNode(" ")); |
1184 | 1197 | } |
1185 | 1198 | selection.insertNodes(nodes); |
| 1199 | + inserted = true; |
1186 | 1200 | }); |
| 1201 | + if (!inserted) { |
| 1202 | + return false; |
| 1203 | + } |
| 1204 | + event.preventDefault(); |
1187 | 1205 | return true; |
1188 | 1206 | }, |
1189 | 1207 | COMMAND_PRIORITY_HIGH, |
|
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/components/files/FileBrowserPanel.tsx +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,13 +110,24 @@ export default function FileBrowserPanel({ |
110 | 110 | return; |
111 | 111 | } |
112 | 112 | if (clicked === "add-to-chat") { |
113 | | - const inserted = composerRef?.current?.insertTextAtEnd(`${mention} `) ?? false; |
114 | | - if (!inserted) { |
| 113 | + const composer = composerRef?.current; |
| 114 | + if (!composer) { |
115 | 115 | toastManager.add({ |
116 | 116 | type: "error", |
117 | 117 | title: "Unable to add to chat", |
118 | 118 | description: "Open a chat for this project and try again.", |
119 | 119 | }); |
| 120 | + return; |
| 121 | + } |
| 122 | + const currentValue = composer.readSnapshot().value; |
| 123 | + const needsLeadingSpace = currentValue.length > 0 && !/\s$/.test(currentValue); |
| 124 | + const inserted = composer.insertTextAtEnd(`${needsLeadingSpace ? " " : ""}${mention} `); |
| 125 | + if (!inserted) { |
| 126 | + toastManager.add({ |
| 127 | + type: "error", |
| 128 | + title: "Unable to add to chat", |
| 129 | + description: "The chat isn't ready to accept input right now.", |
| 130 | + }); |
120 | 131 | } |
121 | 132 | } |
122 | 133 | } finally { |
|