Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
527 changes: 422 additions & 105 deletions src-node/claude-code-agent.js

Large diffs are not rendered by default.

54 changes: 46 additions & 8 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@
* @param {!string} text
*/
Editor.prototype._resetText = function (text) {
var currentText = this._codeMirror.getValue();
var cm = this._codeMirror;
var currentText = cm.getValue();

Check failure on line 721 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVZ&open=AZ3JnyxFFmB-vpwNxkVZ&pullRequest=2849

// compare with ignoring line-endings, issue #11826
var textLF = text ? text.replace(/(\r\n|\r|\n)/g, "\n") : null;
Expand All @@ -732,14 +733,51 @@
var cursorPos = this.getCursorPos(),
scrollPos = this.getScrollPos();

// This *will* fire a change event, but we clear the undo immediately afterward
this._codeMirror.setValue(text);
this._codeMirror.refresh();
// First-time content load (e.g. opening a file): there's no useful
// undo state to preserve — fall back to setValue + clearHistory so
// the user can't ctrl-z into the empty doc that existed before open.
var isInitialLoad = currentText === "" && cm.historySize().undo === 0;

Check failure on line 739 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVa&open=AZ3JnyxFFmB-vpwNxkVa&pullRequest=2849

// Make sure we can't undo back to the empty state before setValue(), and mark
// the document clean.
this._codeMirror.clearHistory();
this._codeMirror.markClean();
if (isInitialLoad) {
cm.setValue(text);
cm.refresh();
cm.clearHistory();
} else {
// External-content reload (disk change, AI edit, git checkout, etc.):
// replace ONLY the differing middle of the document so the change
// is undoable AND CodeMirror marks outside the changed region are
// preserved. The latter matters for HTML files used in live
// preview (each rendered element holds a mark) — replacing the
// whole doc would clear every mark and force a full preview
// refresh on every edit.
//
// O(n) common prefix + suffix scan: cheap enough to apply to all
// languages, and AI edits are typically tiny relative to file size.
var prefixLen = 0;

Check failure on line 756 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVb&open=AZ3JnyxFFmB-vpwNxkVb&pullRequest=2849
var minLen = Math.min(currentText.length, text.length);

Check failure on line 757 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVc&open=AZ3JnyxFFmB-vpwNxkVc&pullRequest=2849
while (prefixLen < minLen &&
currentText.charCodeAt(prefixLen) === text.charCodeAt(prefixLen)) {

Check warning on line 759 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#codePointAt()` over `String#charCodeAt()`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVd&open=AZ3JnyxFFmB-vpwNxkVd&pullRequest=2849

Check warning on line 759 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#codePointAt()` over `String#charCodeAt()`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVe&open=AZ3JnyxFFmB-vpwNxkVe&pullRequest=2849
prefixLen++;
}
var maxSuffix = Math.min(currentText.length - prefixLen, text.length - prefixLen);

Check failure on line 762 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVf&open=AZ3JnyxFFmB-vpwNxkVf&pullRequest=2849
var suffixLen = 0;

Check failure on line 763 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVg&open=AZ3JnyxFFmB-vpwNxkVg&pullRequest=2849
while (suffixLen < maxSuffix &&
currentText.charCodeAt(currentText.length - 1 - suffixLen) ===

Check warning on line 765 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#codePointAt()` over `String#charCodeAt()`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVh&open=AZ3JnyxFFmB-vpwNxkVh&pullRequest=2849
text.charCodeAt(text.length - 1 - suffixLen)) {

Check warning on line 766 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#codePointAt()` over `String#charCodeAt()`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVi&open=AZ3JnyxFFmB-vpwNxkVi&pullRequest=2849
suffixLen++;
}
var fromPos = cm.posFromIndex(prefixLen);

Check failure on line 769 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVj&open=AZ3JnyxFFmB-vpwNxkVj&pullRequest=2849
var toPos = cm.posFromIndex(currentText.length - suffixLen);

Check failure on line 770 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVk&open=AZ3JnyxFFmB-vpwNxkVk&pullRequest=2849
var middle = text.substring(prefixLen, text.length - suffixLen);

Check failure on line 771 in src/editor/Editor.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ3JnyxFFmB-vpwNxkVl&open=AZ3JnyxFFmB-vpwNxkVl&pullRequest=2849
cm.operation(function () {
cm.replaceRange(middle, fromPos, toPos, "+disk");
});
cm.refresh();
}
// markClean sets the new "saved" generation — disk == buffer right
// now, so dirty=false. Undoing past this generation will re-mark
// dirty, exactly like a manual edit.
cm.markClean();

// restore cursor and scroll positions
this.setCursorPos(cursorPos);
Expand Down
17 changes: 17 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,8 @@ define({
"AI_CHAT_TOOL_SEARCHED": "Searched: {0}",
"AI_CHAT_TOOL_GREP": "Grep: {0}",
"AI_CHAT_TOOL_READ_FILE": "Read {0}",
"AI_CHAT_TOOL_READ_FILE_RANGE": "Read {0} lines {1}-{2}",
"AI_CHAT_TOOL_READ_FILE_FROM": "Read {0} from line {1}",
"AI_CHAT_TOOL_EDIT_FILE": "Edit {0}",
"AI_CHAT_TOOL_WRITE_FILE": "Write {0}",
"AI_CHAT_TOOL_RAN_CMD": "Ran command",
Expand All @@ -2214,10 +2216,19 @@ define({
"AI_CHAT_UNDO_TITLE": "Undo changes from this response",
"AI_CHAT_RESTORE_TITLE": "Restore files to this point",
"AI_CHAT_RESTORED": "Restored",
"AI_CHAT_TOOL_APPLIED_DIRECTLY": "Applied directly to disk · diff not available",
"AI_CHAT_TOOL_REJECTED": "Edit rejected — file not modified",
"AI_CHAT_TOOL_REJECTED_REASON": "Reason: {0}",
"AI_CHAT_FILE_NOT_FOUND_TITLE": "File not found",
"AI_CHAT_FILE_NOT_FOUND_MSG": "Could not open <span class=\"dialog-filename\">{0}</span>. The file may have been moved or deleted.",
"AI_CHAT_UNDO_RESTORE_WARNING_TITLE": "AI Undo & Restore",
"AI_CHAT_UNDO_RESTORE_WARNING_BODY": "This will only undo changes made by the AI. Changes made outside the AI won’t be restored and may be lost. For full version history, use version control like Git.",
"AI_CHAT_SHOW_DIFF": "Show diff",
"AI_CHAT_HIDE_DIFF": "Hide diff",
"AI_CHAT_DIFF_MORE_TITLE": "Diff options",
"AI_CHAT_DIFF_EXPAND_ALL": "Expand all",
"AI_CHAT_DIFF_COLLAPSE_ALL": "Collapse all",
"AI_CHAT_DIFF_ALWAYS_SHOW": "Always show",
"AI_CHAT_LABEL_YOU": "You",
"AI_CHAT_LABEL_CLAUDE": "Claude",
"AI_CHAT_SEND_ERROR": "Failed to send message: {0}",
Expand Down Expand Up @@ -2255,6 +2266,12 @@ define({
"AI_CHAT_BASH_DENY": "Deny",
"AI_CHAT_BASH_ALLOWED": "Command allowed",
"AI_CHAT_BASH_DENIED": "Command denied",
"AI_CHAT_PLAN_WRITE_CONFIRM_TITLE": "Switch to Edit Mode?",
"AI_CHAT_PLAN_WRITE_CONFIRM_BODY": "Claude wants to edit {0}. You're currently in Plan Mode.",
"AI_CHAT_PLAN_WRITE_ALLOW": "Allow & Switch to Edit Mode",
"AI_CHAT_PLAN_WRITE_STAY": "Stay in Plan Mode",
"AI_CHAT_PLAN_WRITE_ALLOWED": "Switched to Edit Mode",
"AI_CHAT_PLAN_WRITE_STAYED": "Stayed in Plan Mode",
"AI_CHAT_CODE_DEFAULT_LANG": "text",
"AI_CHAT_CODE_COLLAPSE": "Collapse",
"AI_CHAT_CODE_EXPAND": "Expand",
Expand Down
Loading
Loading