reqable / re-editor

Re-Editor is a powerful lightweight text and code editor widget.
https://pub.dev/packages/re_editor
MIT License
527 stars 51 forks source link

Set cursor focus to end of the line #6

Closed Srimathi622 closed 7 months ago

Srimathi622 commented 8 months ago

Hi, I am using codeLineEditingController.text to set and get the text on the editor. I want to blink the cursor at the end of the line or document. How can I achieve this? I tried the below code while clicking the button. The cursor is not moving to the end. please help me.

setState(() { codeLineEditingController.text = formatted text;

codeLineEditingController .moveCursorToLineEnd(); });

Thanks in advance Srimathi

MegatronKing commented 8 months ago

@Srimathi622 When you click the button, the code editor loses focus and the cursor disappears. All you need to do is use CodeEditorTapRegion to wrap your button. In the latest commit, I set the CodeEditorTapRegion to public, so you can use it directly. If you use a previous version, you can refer to the implementation of CodeEditorTapRegion.

Srimathi622 commented 8 months ago

Thank you for your response. I used the provided code to wrap the button. The editor now has focus, but the cursor is consistently positioned at the beginning of the line. My intention is to focus the cursor at the current position. Here's the code I used:

class CodeEditorTapRegion extends TapRegion {
  const CodeEditorTapRegion({
    required super.child,
    super.onTapOutside,
  }) : super(groupId: CodeEditor);
}

Thanks Srimathi

MegatronKing commented 8 months ago

@Srimathi622 I think you can use selection field of CodeLineEditingController to control your cursor position.

Srimathi622 commented 8 months ago

I tried the below code, but it is only selecting the text. The cursor is not moved to the current place. For example, I am in line 12, I want to focus my cursor point in the same place after clicking the button. codeLineEditingController .selection = CodeLineSelection( baseIndex: 10, baseOffset: 10)

MegatronKing commented 7 months ago

As I said before, you should use CodeEditorTapRegion to keep your editor focus.

MegatronKing commented 7 months ago

I will close this issue as completed.