editor: Change drag_and_drop_selection
cursor on delay elapsed + Add drag_and_drop_selection
delay setting (#33928)
When [`drag_and_drop_selection` is true](https://zed.dev/docs/configuring-zed#drag-and-drop-selection), users can make a selection in the buffer and then drag and drop it to a new location. However, the editor forces users to wait 300ms after mouse down before dragging. If users try to drag before this delay has elapsed, they will create a new text selection instead, which can create the impression that drag and drop does not work. I made two changes to improve the UX of this feature: * If users do not want a delay before drag and drop is enabled, they can set the `drag_and_drop_selection.delay_ms` setting to 0. * If the user has done a mouse down on a text selection, the cursor changes to a copy affordance as soon as the configured delay has elapsed, rather than waiting for them to start dragging. This way they don't need to guess at when the delay has elapsed. The default settings for this feature are now: ``` "drag_and_drop_selection": { "enabled": true, "delay_ms": 300 } ``` Closes #33915 Before: https://github.com/user-attachments/assets/7b2f986f-9c67-4b2b-a10e-757c3e9c934b After: https://github.com/user-attachments/assets/726d0dbf-e58b-41ad-93d2-1a758640b422 Release Notes: - Migrate `drag_and_drop_selection` setting to `drag_and_drop_selection.enabled`. - Add `drag_and_drop_selection.delay_ms` setting to configure the delay that must elapse before drag and drop is allowed. - Show a ready to drag cursor affordance as soon as the delay has elapsed --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
parent
4ed206b37c
commit
1569b662ff
8 changed files with 110 additions and 17 deletions
|
@ -1170,7 +1170,6 @@ pub struct Editor {
|
|||
pub change_list: ChangeList,
|
||||
inline_value_cache: InlineValueCache,
|
||||
selection_drag_state: SelectionDragState,
|
||||
drag_and_drop_selection_enabled: bool,
|
||||
next_color_inlay_id: usize,
|
||||
colors: Option<LspColorData>,
|
||||
folding_newlines: Task<()>,
|
||||
|
@ -2202,7 +2201,6 @@ impl Editor {
|
|||
change_list: ChangeList::new(),
|
||||
mode,
|
||||
selection_drag_state: SelectionDragState::None,
|
||||
drag_and_drop_selection_enabled: EditorSettings::get_global(cx).drag_and_drop_selection,
|
||||
folding_newlines: Task::ready(()),
|
||||
};
|
||||
if let Some(breakpoints) = editor.breakpoint_store.as_ref() {
|
||||
|
@ -19899,7 +19897,6 @@ impl Editor {
|
|||
self.show_breadcrumbs = editor_settings.toolbar.breadcrumbs;
|
||||
self.cursor_shape = editor_settings.cursor_shape.unwrap_or_default();
|
||||
self.hide_mouse_mode = editor_settings.hide_mouse.unwrap_or_default();
|
||||
self.drag_and_drop_selection_enabled = editor_settings.drag_and_drop_selection;
|
||||
}
|
||||
|
||||
if old_cursor_shape != self.cursor_shape {
|
||||
|
|
|
@ -52,7 +52,7 @@ pub struct EditorSettings {
|
|||
#[serde(default)]
|
||||
pub diagnostics_max_severity: Option<DiagnosticSeverity>,
|
||||
pub inline_code_actions: bool,
|
||||
pub drag_and_drop_selection: bool,
|
||||
pub drag_and_drop_selection: DragAndDropSelection,
|
||||
pub lsp_document_colors: DocumentColorsRenderMode,
|
||||
}
|
||||
|
||||
|
@ -275,6 +275,26 @@ pub struct ScrollbarAxes {
|
|||
pub vertical: bool,
|
||||
}
|
||||
|
||||
/// Whether to allow drag and drop text selection in buffer.
|
||||
#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub struct DragAndDropSelection {
|
||||
/// When true, enables drag and drop text selection in buffer.
|
||||
///
|
||||
/// Default: true
|
||||
#[serde(default = "default_true")]
|
||||
pub enabled: bool,
|
||||
|
||||
/// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
|
||||
///
|
||||
/// Default: 300
|
||||
#[serde(default = "default_drag_and_drop_selection_delay_ms")]
|
||||
pub delay: u64,
|
||||
}
|
||||
|
||||
fn default_drag_and_drop_selection_delay_ms() -> u64 {
|
||||
300
|
||||
}
|
||||
|
||||
/// Which diagnostic indicators to show in the scrollbar.
|
||||
///
|
||||
/// Default: all
|
||||
|
@ -536,10 +556,8 @@ pub struct EditorSettingsContent {
|
|||
/// Default: true
|
||||
pub inline_code_actions: Option<bool>,
|
||||
|
||||
/// Whether to allow drag and drop text selection in buffer.
|
||||
///
|
||||
/// Default: true
|
||||
pub drag_and_drop_selection: Option<bool>,
|
||||
/// Drag and drop related settings
|
||||
pub drag_and_drop_selection: Option<DragAndDropSelection>,
|
||||
|
||||
/// How to render LSP `textDocument/documentColor` colors in the editor.
|
||||
///
|
||||
|
|
|
@ -87,7 +87,6 @@ use util::{RangeExt, ResultExt, debug_panic};
|
|||
use workspace::{CollaboratorId, Workspace, item::Item, notifications::NotifyTaskExt};
|
||||
|
||||
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 7.;
|
||||
const SELECTION_DRAG_DELAY: Duration = Duration::from_millis(300);
|
||||
|
||||
/// Determines what kinds of highlights should be applied to a lines background.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
|
@ -644,7 +643,11 @@ impl EditorElement {
|
|||
return;
|
||||
}
|
||||
|
||||
if editor.drag_and_drop_selection_enabled && click_count == 1 {
|
||||
if EditorSettings::get_global(cx)
|
||||
.drag_and_drop_selection
|
||||
.enabled
|
||||
&& click_count == 1
|
||||
{
|
||||
let newest_anchor = editor.selections.newest_anchor();
|
||||
let snapshot = editor.snapshot(window, cx);
|
||||
let selection = newest_anchor.map(|anchor| anchor.to_display_point(&snapshot));
|
||||
|
@ -1022,7 +1025,10 @@ impl EditorElement {
|
|||
ref click_position,
|
||||
ref mouse_down_time,
|
||||
} => {
|
||||
if mouse_down_time.elapsed() >= SELECTION_DRAG_DELAY {
|
||||
let drag_and_drop_delay = Duration::from_millis(
|
||||
EditorSettings::get_global(cx).drag_and_drop_selection.delay,
|
||||
);
|
||||
if mouse_down_time.elapsed() >= drag_and_drop_delay {
|
||||
let drop_cursor = Selection {
|
||||
id: post_inc(&mut editor.selections.next_selection_id),
|
||||
start: drop_anchor,
|
||||
|
@ -5710,6 +5716,19 @@ impl EditorElement {
|
|||
let editor = self.editor.read(cx);
|
||||
if editor.mouse_cursor_hidden {
|
||||
window.set_window_cursor_style(CursorStyle::None);
|
||||
} else if let SelectionDragState::ReadyToDrag {
|
||||
mouse_down_time, ..
|
||||
} = &editor.selection_drag_state
|
||||
{
|
||||
let drag_and_drop_delay = Duration::from_millis(
|
||||
EditorSettings::get_global(cx).drag_and_drop_selection.delay,
|
||||
);
|
||||
if mouse_down_time.elapsed() >= drag_and_drop_delay {
|
||||
window.set_cursor_style(
|
||||
CursorStyle::DragCopy,
|
||||
&layout.position_map.text_hitbox,
|
||||
);
|
||||
}
|
||||
} else if matches!(
|
||||
editor.selection_drag_state,
|
||||
SelectionDragState::Dragging { .. }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue