Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use CMD instead of CTRL for mac for modifier key #1106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
30 changes: 18 additions & 12 deletions h2d/TextInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ private typedef TextHistoryElement = { t : String, c : Int, sel : { start : Int,
**/
class TextInput extends Text {

#if sys
public static final modifierKey: Int = Sys.systemName() == "Mac" ? K.LEFT_WINDOW_KEY : K.CTRL;
#else
public static final modifierKey: Int = K.CTRL;
#end

/**
Current position of the input cursor.
When TextInput is not focused value is -1.
Expand Down Expand Up @@ -165,12 +171,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 +222,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 +256,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 Expand Up @@ -388,7 +394,7 @@ class TextInput extends Text {
}
return '';
}

function getCursorXOffset() {
var lines = getAllLines();
var offset = cursorIndex;
Expand Down Expand Up @@ -522,11 +528,11 @@ class TextInput extends Text {

var selStart = Math.floor(Math.max(0, selectionRange.start - lineOffset));
var selEnd = Math.floor(Math.min(line.length - selStart, selectionRange.length + selectionRange.start - lineOffset - selStart));

selectionPos = calcTextWidth(line.substr(0, selStart));
selectionSize = calcTextWidth(line.substr(selStart, selEnd));
if( selectionRange.start + selectionRange.length == text.length ) selectionSize += cursorTile.width; // last pixel

selectionTile.dx += selectionPos;
selectionTile.dy += i * font.lineHeight;
selectionTile.width += selectionSize;
Expand Down Expand Up @@ -659,4 +665,4 @@ class TextInput extends Text {
function get_backgroundColor() return interactive.backgroundColor;
function set_backgroundColor(v) return interactive.backgroundColor = v;

}
}