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

After two blocks are merged, show cursor on the end of the text field #756

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
927d77c
Send backspace event only when it's clicked second time - in order to…
marecar3 Mar 18, 2019
4c0a6f8
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Mar 18, 2019
87c721b
Fixed problem with selection on block
marecar3 Mar 18, 2019
76f833f
Use custom ArrowKeyMovementMethod for controlling auto selection
marecar3 Mar 19, 2019
7b7aa34
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Mar 19, 2019
c6ab68a
Remove unused imports
marecar3 Mar 19, 2019
6cb0e47
Removed unused log
marecar3 Mar 19, 2019
a0e2b6c
Fixed small typo in the comment
marecar3 Mar 19, 2019
eb241dd
Removed backspace count for detecting backspace on Android platform a…
marecar3 Mar 19, 2019
2f6dbc0
Remove unused imports
marecar3 Mar 19, 2019
1e8a0a8
added a minimal delay to call setSelection() to enforce special focus…
mzorz Mar 20, 2019
2ffc60e
Merge pull request #765 from wordpress-mobile/try/delay-selection-mod…
mzorz Mar 20, 2019
d4b6838
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Mar 22, 2019
3edbbbb
Try to set selection without delay
marecar3 Mar 26, 2019
0213bf8
Move caret on the end when leaving text fields
marecar3 Mar 26, 2019
45a61cf
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Mar 28, 2019
cb83e53
Removed native handling caret logic
marecar3 Apr 4, 2019
44b1d0c
update gutenberg submodule
marecar3 Apr 4, 2019
1e83c7c
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Apr 4, 2019
c8ec4dc
Removed logic which force caret position on the end of text
marecar3 Apr 4, 2019
5aaac21
Updated gutenberg mobile submodule
marecar3 Apr 4, 2019
0d3a4be
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Apr 4, 2019
771f773
Updated gutenberg submodule
marecar3 Apr 4, 2019
e14f550
Remove empty line
marecar3 Apr 4, 2019
7b590bc
Removed unused condition
marecar3 Apr 4, 2019
eb7be19
Updated gutenberg submodule
marecar3 Apr 4, 2019
d9988c1
Updated gutenberg submodule
marecar3 Apr 4, 2019
ac9b40c
Updated gutenberg submodule
marecar3 Apr 4, 2019
2df20ff
Updated gutenberg submodule
marecar3 Apr 4, 2019
e735256
Merge branch 'develop' into fix/699_Deleting-all-contents-of-block-mo…
marecar3 Apr 5, 2019
d0c6d50
Update gutenberg submodule
marecar3 Apr 5, 2019
b02c6a7
Merge
marecar3 Apr 9, 2019
820ceca
Fixed bug on android when merging two block with content
marecar3 Apr 9, 2019
f3ca30b
Updated gutenberg submodule to point to the latest master
marecar3 Apr 10, 2019
3316f60
Updated gutenberg submodule
marecar3 Apr 10, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.wordpress.mobile.ReactNativeAztec;

import android.text.Selection;
import android.text.Spannable;
import android.text.method.ArrowKeyMovementMethod;
import android.view.View;
import android.widget.TextView;

public class ReactAztecArrowKeyMovementMethod extends ArrowKeyMovementMethod {

@Override
public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
if (view.getLayout() == null) {
Selection.setSelection(text, 0); // <-- setting caret to end of text
}
} else {
Selection.setSelection(text, text.length()); // <-- same as original Android implementation. Not sure if we should change this too
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public void onFocusChange(View v, boolean hasFocus) {
}
}
});

// Don't think we need to add setOnEditorActionListener here (intercept Enter for example), but
// in case check ReactTextInputManager
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputType;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.ArrowKeyMovementMethod;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
Expand Down Expand Up @@ -100,11 +96,15 @@ public boolean onEnterKey() {
@Override
public boolean onBackspaceKey() {
if (shouldHandleOnBackspace) {
return onBackspace();
String content = toHtml(false);
if (TextUtils.isEmpty(content)) {
return onBackspace();
}
}
return false;
}
});

mInputMethodManager = (InputMethodManager)
Assertions.assertNotNull(getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
this.setOnSelectionChangedListener(new OnSelectionChangedListener() {
Expand All @@ -122,20 +122,7 @@ private void forceCaretAtStartOnTakeFocus() {
// Fixes https://github.com/wordpress-mobile/gutenberg-mobile/issues/602
// onTakeFocus adapted from the Android source code at:
// https://android.googlesource.com/platform/frameworks/base/+/refs/heads/pie-release/core/java/android/text/method/ArrowKeyMovementMethod.java#316
setMovementMethod(new ArrowKeyMovementMethod() {
@Override
public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
if (view.getLayout() == null) {
// This shouldn't be null, but do something sensible if it is.
Selection.setSelection(text, 0); // <-- setting caret to start of text
}
} else {
Selection.setSelection(text, text.length()); // <-- same as original Android implementation. Not sure if we should change this too
}
}
});

setMovementMethod(new ReactAztecArrowKeyMovementMethod());
}

@Override
Expand Down Expand Up @@ -245,13 +232,14 @@ public void run() {
}

public void setTagName(@Nullable String tagName) {
this.mTagName = tagName;
mTagName = tagName;
}

public String getTagName() {
return this.mTagName;
return mTagName;
}


private void updateToolbarButtons(int selStart, int selEnd) {
ArrayList<ITextFormat> appliedStyles = getAppliedStyles(selStart, selEnd);
updateToolbarButtons(appliedStyles);
Expand Down
2 changes: 1 addition & 1 deletion react-native-aztec/ios/RNTAztecView/RCTAztecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class RCTAztecView: Aztec.TextView {
}
}

func setSelection(start: NSNumber, end: NSNumber) {
func setSelection(start: NSNumber, end: NSNumber) {
if let startPosition = position(from: beginningOfDocument, offset: start.intValue),
let endPosition = position(from: beginningOfDocument, offset: end.intValue) {
selectedTextRange = textRange(from: startPosition, to: endPosition)
Expand Down