8000 WIP: make select whole word on kitkat · bigsharp/python-for-android@80c783d · GitHub
[go: up one dir, main page]

Skip to content

Commit 80c783d

Browse files
committed
WIP: make select whole word on kitkat
1 parent 35246e1 commit 80c783d

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ public interface OnInterceptTouchListener {
342342

343343
// This stores the length of the text in pridiction/swype buffer
344344
private int mDelLen = 0;
345+
private int mRDelLen = 0;
345346

346347
// The width and height. (This should be set at startup time -
347348
// these values just prevent segfaults and divide by zero, etc.)
@@ -363,10 +364,17 @@ public interface OnInterceptTouchListener {
363364
// Text before/after cursor
364365
static String mTbf = " ";
365366
static String mTaf = " ";
367+
static InputConnection ic = null;
366368

367-
public static void updateTextFromCursor(String bef, String aft){
369+
public static void updateTextFromCursor(String bef, String aft, int compose){
368370
mTbf = bef;
369371
mTaf = aft;
372+
ic.getTextBeforeCursor(1024, 0);
373+
ic.getTextAfterCursor(1024, 0);
374+
int length = mTbf.length();
375+
if (compose == 1 && length > 0){
376+
ic.setComposingRegion(length - 1, length);
377+
}
370378
if (DEBUG) Log.d(TAG, String.format("mtbf: %s mtaf:%s <<<<<<<<<", mTbf, mTaf));
371379
}
372380

@@ -1168,17 +1176,17 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
11681176
outAttrs.inputType = inputType;
11691177
// ask IME to avoid taking full screen on landscape mode
11701178
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
1171-
return new BaseInputConnection(this, false){
1179+
ic = new BaseInputConnection(this, false){
11721180

11731181
private void deleteLastText(){
11741182
// send back space keys
11751183
if (DEBUG) Log.i("Python:", String.format("delete text%s", mDelLen));
11761184

1177-
if (mDelLen == 0){
1178-
return;
1179-
}
1185+
String message = "";
11801186

1181-
String message = String.format("DEL:%s", mDelLen);
1187+
if (mDelLen == 0) return;
1188+
1189+
message = String.format("DEL:%s", mDelLen);
11821190
dispatchCommand(message);
11831191
}
11841192

@@ -1200,12 +1208,6 @@ public boolean commitCompletion(CompletionInfo text){
12001208
return super.commitCompletion(text);
12011209
}
12021210

1203-
@Override
1204-
public boolean commitCorrection(CorrectionInfo correctionInfo){
1205-
if (DEBUG) Log.i("Python:", String.format("Commit Correction"));
1206-
return super.commitCorrection(correctionInfo);
1207-
}
1208-
12091211
@Override
12101212
public boolean commitText(CharSequence text, int newCursorPosition) {
12111213
// some code which takes the input and manipulates it and calls editText.getText().replace() afterwards
@@ -1223,17 +1225,11 @@ public boolean sendKeyEvent(KeyEvent event){
12231225

12241226
@Override
12251227
public boolean setComposingRegion(int start, int end){
1226-
if (DEBUG) Log.d("Python:", String.format("Set Composing Region %s %s", start, end));
1227-
//finishComposingText();
1228-
if (start < 0 || start > end)
1228+
if (start < 0 || start > end || start == end)
12291229
return true;
1230-
//if (start > 0) start -= 1;
1231-
end = Math.min(end, mTbf.length());
1232-
if (end < 0) end = 0;
1233-
dispatchCommand(String.format("SEL:%s,%s,%s", mTbf.length(), start, end));
1234-
this.setComposingText(mTbf.substring(start, end), 1);
1235-
return true;
1236-
//return super.setComposingRegion(start, end);
1230+
dispatchCommand(String.format("SELWORD:"));
1231+
Log.d("Python:", String.format("%s, %s", mRDelLen, mTbf));
1232+
return super.setComposingRegion(start, end);
12371233
}
12381234

12391235
@Override
@@ -1252,6 +1248,7 @@ public boolean setComposingText(CharSequence text,
12521248
@Override
12531249
public boolean finishComposingText(){
12541250
if (DEBUG) Log.i("Python:", String.format("finish Composing Text"));
1251+
dispatchCommand(String.format("SEL:0"));
12551252
return super.finishComposingText();
12561253
}
12571254

@@ -1260,10 +1257,6 @@ public boolean deleteSurroundingText (int beforeLength, int afterLength){
12601257
if (DEBUG) Log.d("Python:", String.format("delete surrounding Text %s %s", beforeLength, afterLength));
12611258
// move cursor to place from where to start deleting
12621259
// send right arrow keys
1263-
for (int i = 0; i < afterLength; i++){
1264-
nativeKey(45, 1, 39);
1265-
nativeKey(45, 0, 39);
1266-
}
12671260
// remove text before cursor
12681261
mDelLen = beforeLength + afterLength;
12691262
this.deleteLastText();
@@ -1308,6 +1301,7 @@ public boolean setSelection(int start, int end){
13081301
return super.setSelection(start, end);
13091302
}
13101303
};
1304+
return ic;
13111305
}
13121306

13131307
static void activateInput() {

0 commit comments

Comments
 (0)
0