Skip to content

Commit 2f19106

Browse files
Follow up page context redux (#1960)
* Trim whitespace from links * Don't create context chip if context has been used * Add belt and braces fix for enter submission
1 parent 7224654 commit 2f19106

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

injected/src/features/duck-ai-listener.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,15 @@ export default class DuckAiListener extends ContentFeature {
870870
if (match) {
871871
const extractedPrompt = match[2].trim();
872872

873+
// Mark context as used since we found a prompt that was actually sent
874+
// Belt and braces solution to ensure context is only used once
875+
if (!this.hasContextBeenUsed) {
876+
this.hasContextBeenUsed = true;
877+
this.removeContextChip();
878+
this.updateButtonAppearance();
879+
this.log.info('Context marked as used based on prompt cleanup');
880+
}
881+
873882
// Create cleaned content
874883
let cleanedContent = '';
875884
if (extractedPrompt) {
@@ -977,7 +986,7 @@ export default class DuckAiListener extends ContentFeature {
977986
const callback = (_, observer) => {
978987
this.findTextBox();
979988
this.setupMessageInterception();
980-
if (this.textBox && this.pageData && this.sendButton) {
989+
if (this.textBox && this.pageData && this.sendButton && !this.hasContextBeenUsed) {
981990
this.createContextChip();
982991
// No longer needed, we've found the text box.
983992
observer.disconnect();

injected/src/features/page-context.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ function domToMarkdown(node, maxLength = Infinity) {
5757
}
5858
}
5959

60+
function collapseAndTrim(str) {
61+
return collapseWhitespace(str).trim();
62+
}
63+
6064
function getLinkText(node) {
6165
const href = node.getAttribute('href');
62-
return href ? `[${node.textContent}](${href})` : node.textContent;
66+
return href ? `[${collapseAndTrim(node.textContent)}](${href})` : collapseWhitespace(node.textContent);
6367
}
6468

6569
export default class PageContext extends ContentFeature {

0 commit comments

Comments
 (0)