GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • apps/web/src/components
    • ComposerPromptEditor.tsx
    • files
      • FileBrowserPanel.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ComposerPromptEditor.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditor.tsx
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ function ComposerInlineTokenPastePlugin() {
11441144
if (mentions.length === 0) {
11451145
return false;
11461146
}
1147-
event.preventDefault();
1147+
let inserted = false;
11481148
editor.update(() => {
11491149
const selection = $getSelection();
11501150
if (!$isRangeSelection(selection)) {
@@ -1163,6 +1163,19 @@ function ComposerInlineTokenPastePlugin() {
11631163
}
11641164
}
11651165
};
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+
}
11661179
let cursor = 0;
11671180
for (const mention of mentions) {
11681181
if (mention.start < cursor) {
@@ -1183,7 +1196,12 @@ function ComposerInlineTokenPastePlugin() {
11831196
nodes.push($createTextNode(" "));
11841197
}
11851198
selection.insertNodes(nodes);
1199+
inserted = true;
11861200
});
1201+
if (!inserted) {
1202+
return false;
1203+
}
1204+
event.preventDefault();
11871205
return true;
11881206
},
11891207
COMMAND_PRIORITY_HIGH,
Collapse file

‎apps/web/src/components/files/FileBrowserPanel.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/FileBrowserPanel.tsx
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,24 @@ export default function FileBrowserPanel({
110110
return;
111111
}
112112
if (clicked === "add-to-chat") {
113-
const inserted = composerRef?.current?.insertTextAtEnd(`${mention} `) ?? false;
114-
if (!inserted) {
113+
const composer = composerRef?.current;
114+
if (!composer) {
115115
toastManager.add({
116116
type: "error",
117117
title: "Unable to add to chat",
118118
description: "Open a chat for this project and try again.",
119119
});
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+
});
120131
}
121132
}
122133
} finally {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.