editor: Support both cursor and mouse based columnar selection (#32779)
Closes #32584 In https://github.com/zed-industries/zed/pull/31888, we changed the default `opt + shift` behavior to start columnar selection from the mouse position (Sublime-like behavior) instead of from the existing selection head (VSCode-like behavior). It turns out there is a use case for creating columnar selection from an existing selection head as well, such as creating a consecutive multi-cursor from existing selection head with just a click instead of dragging. This PR brings back columnar selection from the selection head via `opt + shift`, while retaining columnar selection from the mouse position, which is now mapped to the new `cmd + shift` binding. Note: If you like to swap the binding, you can use [existing multi cursor modifier setting](https://zed.dev/docs/configuring-zed?highlight=multi_cursor_modifier#multi-cursor-modifier). Release Notes: - Added `cmd + shift` to start columnar selection from the mouse position. - Restored `opt + shift` to create columnar selection (or consecutive multi-cursor on click) from the selection head.
This commit is contained in:
parent
6150c26bd2
commit
ef61ebe049
2 changed files with 116 additions and 64 deletions
|
@ -1,13 +1,13 @@
|
|||
use crate::{
|
||||
ActiveDiagnostic, BlockId, CURSORS_VISIBLE_FOR, ChunkRendererContext, ChunkReplacement,
|
||||
CodeActionSource, ConflictsOurs, ConflictsOursMarker, ConflictsOuter, ConflictsTheirs,
|
||||
ConflictsTheirsMarker, ContextMenuPlacement, CursorShape, CustomBlockId, DisplayDiffHunk,
|
||||
DisplayPoint, DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, EditDisplayMode,
|
||||
Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, FILE_HEADER_HEIGHT,
|
||||
FocusedBlock, GutterDimensions, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor,
|
||||
InlayHintRefreshReason, InlineCompletion, JumpData, LineDown, LineHighlight, LineUp,
|
||||
MAX_LINE_LEN, MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT, OpenExcerpts, PageDown,
|
||||
PageUp, PhantomBreakpointIndicator, Point, RowExt, RowRangeExt, SelectPhase,
|
||||
CodeActionSource, ColumnarMode, ConflictsOurs, ConflictsOursMarker, ConflictsOuter,
|
||||
ConflictsTheirs, ConflictsTheirsMarker, ContextMenuPlacement, CursorShape, CustomBlockId,
|
||||
DisplayDiffHunk, DisplayPoint, DisplayRow, DocumentHighlightRead, DocumentHighlightWrite,
|
||||
EditDisplayMode, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
||||
FILE_HEADER_HEIGHT, FocusedBlock, GutterDimensions, HalfPageDown, HalfPageUp, HandleInput,
|
||||
HoveredCursor, InlayHintRefreshReason, InlineCompletion, JumpData, LineDown, LineHighlight,
|
||||
LineUp, MAX_LINE_LEN, MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT, OpenExcerpts,
|
||||
PageDown, PageUp, PhantomBreakpointIndicator, Point, RowExt, RowRangeExt, SelectPhase,
|
||||
SelectedTextHighlight, Selection, SelectionDragState, SoftWrap, StickyHeaderExcerpt, ToPoint,
|
||||
ToggleFold,
|
||||
code_context_menus::{CodeActionsMenu, MENU_ASIDE_MAX_WIDTH, MENU_ASIDE_MIN_WIDTH, MENU_GAP},
|
||||
|
@ -700,12 +700,15 @@ impl EditorElement {
|
|||
}
|
||||
|
||||
let position = point_for_position.previous_valid;
|
||||
let multi_cursor_modifier = Editor::multi_cursor_modifier(true, &modifiers, cx);
|
||||
if Editor::columnar_selection_modifiers(multi_cursor_modifier, &modifiers) {
|
||||
if let Some(mode) = Editor::columnar_selection_mode(&modifiers, cx) {
|
||||
editor.select(
|
||||
SelectPhase::BeginColumnar {
|
||||
position,
|
||||
reset: true,
|
||||
reset: match mode {
|
||||
ColumnarMode::FromMouse => true,
|
||||
ColumnarMode::FromSelection => false,
|
||||
},
|
||||
mode: mode,
|
||||
goal_column: point_for_position.exact_unclipped.column(),
|
||||
},
|
||||
window,
|
||||
|
@ -725,7 +728,7 @@ impl EditorElement {
|
|||
editor.select(
|
||||
SelectPhase::Begin {
|
||||
position,
|
||||
add: multi_cursor_modifier,
|
||||
add: Editor::multi_cursor_modifier(true, &modifiers, cx),
|
||||
click_count,
|
||||
},
|
||||
window,
|
||||
|
@ -822,6 +825,7 @@ impl EditorElement {
|
|||
SelectPhase::BeginColumnar {
|
||||
position,
|
||||
reset: true,
|
||||
mode: ColumnarMode::FromMouse,
|
||||
goal_column: point_for_position.exact_unclipped.column(),
|
||||
},
|
||||
window,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue