Skip to content

Commit

Permalink
CE: Add undo steps
Browse files Browse the repository at this point in the history
  • Loading branch information
jxarco committed Jan 30, 2024
1 parent 9277405 commit 5b9c8d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
43 changes: 29 additions & 14 deletions build/components/codeeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1888,26 +1888,14 @@ class CodeEditor {
switch( key.toLowerCase() ) {
case 'a': // select all
e.preventDefault();
this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP );
this.startSelection( cursor );
const nlines = this.code.lines.length - 1;
this.selection.toX = this.code.lines[ nlines ].length;
this.selection.toY = nlines;
this.cursorToPosition( cursor, this.selection.toX );
this.cursorToLine( cursor, this.selection.toY );
this.processSelection( null, true );
this.hideAutoCompleteBox();
this.selectAll( cursor );
break;
case 'c': // copy
this._copyContent();
return;
case 'd': // duplicate line
e.preventDefault();
this.endSelection();
this.code.lines.splice( lidx, 0, this.code.lines[ lidx ] );
this.lineDown( cursor );
this.processLines();
this.hideAutoCompleteBox();
this._duplicateLine( lidx, cursor );
return;
case 'f': // find/search
e.preventDefault();
Expand Down Expand Up @@ -1963,6 +1951,7 @@ class CodeEditor {
case 'ArrowUp':
if(this.code.lines[ lidx - 1 ] == undefined)
return;
this._addUndoStep( cursor, true );
swapArrayElements(this.code.lines, lidx - 1, lidx);
this.lineUp();
this.processLine( lidx - 1 );
Expand All @@ -1972,6 +1961,7 @@ class CodeEditor {
case 'ArrowDown':
if(this.code.lines[ lidx + 1 ] == undefined)
return;
this._addUndoStep( cursor, true );
swapArrayElements(this.code.lines, lidx, lidx + 1);
this.lineDown();
this.processLine( lidx );
Expand Down Expand Up @@ -2152,6 +2142,16 @@ class CodeEditor {
navigator.clipboard.writeText( text_to_cut ).then(() => console.log("Successfully cut"), (err) => console.error("Error"));
}

_duplicateLine( lidx, cursor ) {

this.endSelection();
this._addUndoStep( cursor, true );
this.code.lines.splice( lidx, 0, this.code.lines[ lidx ] );
this.lineDown( cursor );
this.processLines();
this.hideAutoCompleteBox();
}

action( key, deleteSelection, fn ) {

this.actions[ key ] = {
Expand Down Expand Up @@ -2805,6 +2805,19 @@ class CodeEditor {
delete this._lastSelectionKeyDir;
}

selectAll( cursor ) {

this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP );
this.startSelection( cursor );
const nlines = this.code.lines.length - 1;
this.selection.toX = this.code.lines[ nlines ].length;
this.selection.toY = nlines;
this.cursorToPosition( cursor, this.selection.toX );
this.cursorToLine( cursor, this.selection.toY );
this.processSelection( null, true );
this.hideAutoCompleteBox();
}

cursorToRight( key, cursor ) {

if( !key ) return;
Expand Down Expand Up @@ -3320,8 +3333,10 @@ class CodeEditor {

hideAutoCompleteBox() {

const isActive = this.isAutoCompleteActive;
this.isAutoCompleteActive = false;
this.autocomplete.classList.remove( 'show' );
return isActive != this.isAutoCompleteActive;
}

autoCompleteWord( cursor, suggestion ) {
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# lexgui.js changelog

## 0.1.23

Add Undo Steps to some actions that were missing.
General bug fixes.

## 0.1.22

Added REDO using "Ctrl+Y".
Expand Down

0 comments on commit 5b9c8d3

Please sign in to comment.