File tree Expand file tree Collapse file tree
scintilla-extension/module Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " lynxtron-go " : patch
3+ ---
4+
5+ Prevent Cmd+Z from clearing an untouched editor after Lynxtron Go loads a file.
Original file line number Diff line number Diff line change @@ -480,6 +480,15 @@ static bool ScxVerbose() {
480480 if (current == text) return ;
481481 }
482482 [container.scintillaView message: SCI_SETTEXT wParam: 0 lParam: (sptr_t )text.c_str ()];
483+ // Host-driven replacement is a document load, not a user edit.
484+ // SCI_SETTEXT records the inserted document in Scintilla's undo
485+ // history, so the first Cmd+Z on an untouched editor otherwise
486+ // removes the entire file. Also discard history from the previously
487+ // displayed IDE tab: applying that history to this document would be
488+ // equally incorrect. User edits made after this point are collected
489+ // normally and remain undoable.
490+ [container.scintillaView message: SCI_EMPTYUNDOBUFFER wParam: 0 lParam: 0 ];
491+ [container.scintillaView message: SCI_SETSAVEPOINT wParam: 0 lParam: 0 ];
483492 [container.scintillaView setNeedsDisplay: YES ];
484493 };
485494 if ([NSThread isMainThread ]) {
Original file line number Diff line number Diff line change 1+ import fs from 'node:fs' ;
2+ import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
4+ import { describe , expect , it } from 'vitest' ;
5+
6+ const TEST_DIR = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7+ const SCINTILLA_VIEW_SOURCE = path . resolve (
8+ TEST_DIR ,
9+ '../../../scintilla-extension/module/scintilla_view.mm' ,
10+ ) ;
11+
12+ describe ( 'Scintilla host content replacement' , ( ) => {
13+ it ( 'starts loaded documents with an empty native undo history' , ( ) => {
14+ const source = fs . readFileSync ( SCINTILLA_VIEW_SOURCE , 'utf8' ) ;
15+ const setContent = source . slice (
16+ source . indexOf ( 'void ScintillaView::SetContent' ) ,
17+ source . indexOf ( 'std::string ScintillaView::GetContent' ) ,
18+ ) ;
19+
20+ const setText = setContent . indexOf ( 'message:SCI_SETTEXT' ) ;
21+ const emptyUndo = setContent . indexOf ( 'message:SCI_EMPTYUNDOBUFFER' , setText ) ;
22+ const savePoint = setContent . indexOf ( 'message:SCI_SETSAVEPOINT' , emptyUndo ) ;
23+
24+ expect ( setText ) . toBeGreaterThanOrEqual ( 0 ) ;
25+ expect ( emptyUndo ) . toBeGreaterThan ( setText ) ;
26+ expect ( savePoint ) . toBeGreaterThan ( emptyUndo ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments