AI edit: support CURSOR insert at caret position
This commit is contained in:
@@ -1055,6 +1055,11 @@ async function sendAiChat() {
|
|||||||
content.value = content.value.trimEnd() + '\n\n' + editContent
|
content.value = content.value.trimEnd() + '\n\n' + editContent
|
||||||
} else if (hint === 'PREPEND') {
|
} else if (hint === 'PREPEND') {
|
||||||
content.value = editContent + '\n\n' + content.value
|
content.value = editContent + '\n\n' + content.value
|
||||||
|
} else if (hint === 'CURSOR' || hint === 'INSERT') {
|
||||||
|
// Insert at cursor position
|
||||||
|
const ta = editor.value
|
||||||
|
const pos = ta ? ta.selectionStart : content.value.length
|
||||||
|
content.value = content.value.substring(0, pos) + editContent + content.value.substring(pos)
|
||||||
} else {
|
} else {
|
||||||
// REPLACE or unknown — replace entire document
|
// REPLACE or unknown — replace entire document
|
||||||
content.value = hint === 'REPLACE' ? editContent : fullText
|
content.value = hint === 'REPLACE' ? editContent : fullText
|
||||||
|
|||||||
+5
-5
@@ -158,11 +158,11 @@ func (s *Server) handleAIChat(w http.ResponseWriter, r *http.Request) {
|
|||||||
var systemPrompt, userMsg string
|
var systemPrompt, userMsg string
|
||||||
if req.Mode == "edit" {
|
if req.Mode == "edit" {
|
||||||
systemPrompt = "You are a document editor. The user will give you a markdown document and an instruction. " +
|
systemPrompt = "You are a document editor. The user will give you a markdown document and an instruction. " +
|
||||||
"Return ONLY the new or changed text that should be inserted/replaced. " +
|
"Return ONLY the new or changed text. Do not return the entire document unless asked to rewrite it. " +
|
||||||
"Do not return the entire document. Do not add explanations or wrap in code fences. " +
|
"Do not add explanations or wrap in code fences. " +
|
||||||
"If adding content, return only the addition. If modifying, return only the modified section. " +
|
"Start your response with a location hint on the first line: " +
|
||||||
"Start your response with a location hint on the first line: APPEND (add to end), PREPEND (add to start), or REPLACE (replace entire document). " +
|
"APPEND (add to end), PREPEND (add to start), CURSOR (insert at cursor position), or REPLACE (replace entire document). " +
|
||||||
"Then the content on the next line."
|
"Then the content on the next line. Use CURSOR when the user says 'here' or the instruction implies inserting at a specific point."
|
||||||
userMsg = "Document:\n\n" + req.Content + "\n\nInstruction: " + req.Message
|
userMsg = "Document:\n\n" + req.Content + "\n\nInstruction: " + req.Message
|
||||||
} else {
|
} else {
|
||||||
systemPrompt = "You are a helpful writing assistant. The user has a markdown document open. Answer concisely in markdown."
|
systemPrompt = "You are a helpful writing assistant. The user has a markdown document open. Answer concisely in markdown."
|
||||||
|
|||||||
Reference in New Issue
Block a user