Skip to content

Commit

Permalink
use command instead of control for mac for modifier key
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwodahS committed Oct 10, 2022
1 parent 901b39f commit ebb2454
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions h2d/TextInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ private typedef TextHistoryElement = { t : String, c : Int, sel : { start : Int,
**/
class TextInput extends Text {

public static final modifierKey: Int = Sys.systemName() == "Mac" ? K.LEFT_WINDOW_KEY : K.CTRL;

/**
Current position of the input cursor.
When TextInput is not focused value is -1.
Expand Down Expand Up @@ -165,12 +167,12 @@ class TextInput extends Text {
var oldText = text;

switch( e.keyCode ) {
case K.LEFT if (K.isDown(K.CTRL)):
case K.LEFT if (K.isDown(modifierKey)):
cursorIndex = getWordStart();
case K.LEFT:
if( cursorIndex > 0 )
cursorIndex--;
case K.RIGHT if (K.isDown(K.CTRL)):
case K.RIGHT if (K.isDown(modifierKey)):
cursorIndex = getWordEnd();
case K.RIGHT:
if( cursorIndex < text.length )
Expand Down Expand Up @@ -216,32 +218,32 @@ class TextInput extends Text {
cursorIndex++;
onChange();
}
case K.Z if( K.isDown(K.CTRL) ):
case K.Z if( K.isDown(modifierKey) ):
if( undo.length > 0 && canEdit ) {
redo.push(curHistoryState());
setState(undo.pop());
onChange();
}
return;
case K.Y if( K.isDown(K.CTRL) ):
case K.Y if( K.isDown(modifierKey) ):
if( redo.length > 0 && canEdit ) {
undo.push(curHistoryState());
setState(redo.pop());
onChange();
}
return;
case K.A if (K.isDown(K.CTRL)):
case K.A if (K.isDown(modifierKey)):
if (text != "") {
cursorIndex = text.length;
selectionRange = {start: 0, length: text.length};
selectionSize = 0;
}
return;
case K.C if (K.isDown(K.CTRL)):
case K.C if (K.isDown(modifierKey)):
if( text != "" && selectionRange != null ) {
hxd.System.setClipboardText(text.substr(selectionRange.start, selectionRange.length));
}
case K.X if (K.isDown(K.CTRL)):
case K.X if (K.isDown(modifierKey)):
if( text != "" && selectionRange != null ) {
if(hxd.System.setClipboardText(text.substr(selectionRange.start, selectionRange.length))) {
if( !canEdit ) return;
Expand All @@ -250,7 +252,7 @@ class TextInput extends Text {
onChange();
}
}
case K.V if (K.isDown(K.CTRL)):
case K.V if (K.isDown(modifierKey)):
if( !canEdit ) return;
var t = hxd.System.getClipboardText();
if( t != null && t.length > 0 ) {
Expand Down

0 comments on commit ebb2454

Please sign in to comment.