Skip to content

Commit

Permalink
feat: enable shift+press for selection range (AppFlowy-IO#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin authored Oct 2, 2023
1 parent 0fdca2f commit b733864
Showing 1 changed file with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/flutter/overlay.dart';
import 'package:appflowy_editor/src/service/selection/selection_gesture.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class DesktopSelectionServiceWidget extends StatefulWidget {
Expand Down Expand Up @@ -198,24 +199,35 @@ class _DesktopSelectionServiceWidgetState
);
if (!canTap) return;

// clear old state.
_panStartOffset = null;

final offset = details.globalPosition;
final node = getNodeInOffset(offset);
final selectable = node?.selectable;
if (selectable == null) {
clearSelection();
return;
// Clear old start offset
_panStartOffset = null;
return clearSelection();
}
final selection = selectable.cursorStyle == CursorStyle.verticalLine
? Selection.collapsed(
selectable.getPositionInOffset(offset),
)
: Selection(
start: selectable.start(),
end: selectable.end(),
);

Selection? selection;
if (RawKeyboard.instance.isShiftPressed && _panStartOffset != null) {
final first = getNodeInOffset(_panStartOffset!)?.selectable;

if (first != null) {
final start = first.getSelectionInRange(_panStartOffset!, offset).start;
final end =
selectable.getSelectionInRange(_panStartOffset!, offset).end;

selection = Selection(start: start, end: end);
}
} else {
selection = selectable.cursorStyle == CursorStyle.verticalLine
? Selection.collapsed(selectable.getPositionInOffset(offset))
: Selection(start: selectable.start(), end: selectable.end());

// Reset old start offset
_panStartOffset = offset;
}

updateSelection(selection);
}

Expand Down

0 comments on commit b733864

Please sign in to comment.