Skip to content

Commit 4e98cec

Browse files
committed
No deprecated methods no more.
1 parent 3d3086a commit 4e98cec

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

buttons-clicking-deepseek.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// buttons-clicking-deepseek.js
2+
23
// Version: 2.0 - Robust implementation
4+
35
// Handles DeepSeek input and sending with multiple fallbacks
46

57
'use strict';
@@ -43,13 +45,32 @@ function processDeepSeekCustomSendButtonClick(event, customText, autoSend) {
4345

4446
// For contenteditable divs
4547
if (editor.hasAttribute('contenteditable')) {
46-
const range = document.createRange();
48+
// Modern alternative to deprecated document.execCommand:
4749
const selection = window.getSelection();
48-
range.selectNodeContents(editor);
49-
range.collapse(false);
50-
selection.removeAllRanges();
51-
selection.addRange(range);
52-
document.execCommand('insertText', false, text);
50+
let range;
51+
if (selection && selection.rangeCount > 0) {
52+
// Use current selection range if available
53+
range = selection.getRangeAt(0);
54+
} else {
55+
// Create a new range at the end of the editor if no selection exists
56+
range = document.createRange();
57+
range.selectNodeContents(editor);
58+
range.collapse(false);
59+
if (selection) {
60+
selection.removeAllRanges();
61+
selection.addRange(range);
62+
}
63+
}
64+
// Insert text node at the current caret position
65+
const textNode = document.createTextNode(text);
66+
range.insertNode(textNode);
67+
// Move caret immediately after inserted text
68+
range.setStartAfter(textNode);
69+
range.collapse(true);
70+
if (selection) {
71+
selection.removeAllRanges();
72+
selection.addRange(range);
73+
}
5374
editor.dispatchEvent(new Event('input', { bubbles: true }));
5475
return;
5576
}
@@ -120,5 +141,4 @@ function processDeepSeekCustomSendButtonClick(event, customText, autoSend) {
120141
}
121142
}
122143

123-
124-
window.processDeepSeekCustomSendButtonClick = processDeepSeekCustomSendButtonClick;
144+
window.processDeepSeekCustomSendButtonClick = processDeepSeekCustomSendButtonClick;

0 commit comments

Comments
 (0)