소스 검색

use onTap and onDoubleTap for the logic

onTapDown and onDoubleTapDown are used to get the position
adds wordSeparatorCodes so that the list of characters that are word separators can be easily extended.
DoubleTap on a completely selected row selects the word under the mouse pointer again
devmil 4 년 전
부모
커밋
1b426c57d5
2개의 변경된 파일31개의 추가작업 그리고 12개의 파일을 삭제
  1. 16 9
      lib/frontend/terminal_view.dart
  2. 15 3
      lib/terminal/terminal.dart

+ 16 - 9
lib/frontend/terminal_view.dart

@@ -97,6 +97,7 @@ class _TerminalViewState extends State<TerminalView> {
   }
 
   late CellSize _cellSize;
+  Position? _tapPosition;
 
   /// Scroll position from the terminal. Not null if terminal scroll extent has
   /// been updated and needs to be syncronized to flutter side.
@@ -224,22 +225,28 @@ class _TerminalViewState extends State<TerminalView> {
       dragStartBehavior: DragStartBehavior.down,
       onDoubleTapDown: (detail) {
         final pos = detail.localPosition;
-        final offset = getMouseOffset(pos.dx, pos.dy);
-        widget.terminal.onMouseDoubleTap(offset);
-        widget.terminal.refresh();
+        _tapPosition = getMouseOffset(pos.dx, pos.dy);
       },
-      // this is needed to activate double tap
-      onDoubleTap: () {},
       onTapDown: (detail) {
+        final pos = detail.localPosition;
+        _tapPosition = getMouseOffset(pos.dx, pos.dy);
+      },
+      onDoubleTap: () {
+        if (_tapPosition != null) {
+          widget.terminal.onMouseDoubleTap(_tapPosition!);
+          widget.terminal.refresh();
+        }
+      },
+      onTap: () {
         if (widget.terminal.selection?.isEmpty ?? true) {
           InputListener.of(context)!.requestKeyboard();
         } else {
           widget.terminal.clearSelection();
         }
-        final pos = detail.localPosition;
-        final offset = getMouseOffset(pos.dx, pos.dy);
-        widget.terminal.onMouseTap(offset);
-        widget.terminal.refresh();
+        if (_tapPosition != null) {
+          widget.terminal.onMouseTap(_tapPosition!);
+          widget.terminal.refresh();
+        }
       },
       onPanStart: (detail) {
         final pos = detail.localPosition;

+ 15 - 3
lib/terminal/terminal.dart

@@ -466,6 +466,14 @@ class Terminal with Observable implements TerminalUiInteraction {
     }
   }
 
+  final wordSeparatorCodes = <String>[
+    String.fromCharCode(0),
+    ' ',
+    '.',
+    ':',
+    '/'
+  ];
+
   void selectWordOrRow(Position position) {
     if (position.y > buffer.lines.length) {
       return;
@@ -475,7 +483,11 @@ class Terminal with Observable implements TerminalUiInteraction {
 
     final line = buffer.lines[row];
 
-    if (_selection.contains(position)) {
+    final positionIsInSelection = _selection.contains(position);
+    final completeLineIsSelected =
+        _selection.start?.x == 0 && _selection.end?.x == terminalWidth;
+
+    if (positionIsInSelection && !completeLineIsSelected) {
       // select area on an already existing selection extends it to the full line
       _selection.clear();
       _selection.init(Position(0, row));
@@ -491,7 +503,7 @@ class Terminal with Observable implements TerminalUiInteraction {
           break;
         }
         final content = line.cellGetContent(start - 1);
-        if (content == 0 || content == ' '.runes.first) {
+        if (wordSeparatorCodes.contains(String.fromCharCode(content))) {
           break;
         }
         start--;
@@ -501,7 +513,7 @@ class Terminal with Observable implements TerminalUiInteraction {
           break;
         }
         final content = line.cellGetContent(end + 1);
-        if (content == 0 || content == ' '.runes.first) {
+        if (wordSeparatorCodes.contains(String.fromCharCode(content))) {
           break;
         }
         end++;