3819 lines · 120.6 KB · Rust
RawDownload
use editor::{    Anchor, Bias, DisplayPoint, Editor, RowExt, ToOffset, ToPoint,    display_map::{DisplayRow, DisplaySnapshot, FoldPoint, ToDisplayPoint},    movement::{        self, FindRange, TextLayoutDetails, find_boundary, find_preceding_boundary_display_point,    },    scroll::Autoscroll,};use gpui::{Context, Window, action_with_deprecated_aliases, actions, impl_actions, px};use language::{CharKind, Point, Selection, SelectionGoal};use multi_buffer::MultiBufferRow;use schemars::JsonSchema;use serde::Deserialize;use std::ops::Range;use workspace::searchable::Direction; use crate::{    Vim,    normal::mark,    state::{Mode, Operator},    surrounds::SurroundsType,}; #[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum MotionKind {    Linewise,    Exclusive,    Inclusive,} impl MotionKind {    pub(crate) fn for_mode(mode: Mode) -> Self {        match mode {            Mode::VisualLine => MotionKind::Linewise,            _ => MotionKind::Exclusive,        }    }     pub(crate) fn linewise(&self) -> bool {        matches!(self, MotionKind::Linewise)    }} #[derive(Clone, Debug, PartialEq, Eq)]pub enum Motion {    Left,    WrappingLeft,    Down {        display_lines: bool,    },    Up {        display_lines: bool,    },    Right,    WrappingRight,    NextWordStart {        ignore_punctuation: bool,    },    NextWordEnd {        ignore_punctuation: bool,    },    PreviousWordStart {        ignore_punctuation: bool,    },    PreviousWordEnd {        ignore_punctuation: bool,    },    NextSubwordStart {        ignore_punctuation: bool,    },    NextSubwordEnd {        ignore_punctuation: bool,    },    PreviousSubwordStart {        ignore_punctuation: bool,    },    PreviousSubwordEnd {        ignore_punctuation: bool,    },    FirstNonWhitespace {        display_lines: bool,    },    CurrentLine,    StartOfLine {        display_lines: bool,    },    EndOfLine {        display_lines: bool,    },    SentenceBackward,    SentenceForward,    StartOfParagraph,    EndOfParagraph,    StartOfDocument,    EndOfDocument,    Matching,    GoToPercentage,    UnmatchedForward {        char: char,    },    UnmatchedBackward {        char: char,    },    FindForward {        before: bool,        char: char,        mode: FindRange,        smartcase: bool,    },    FindBackward {        after: bool,        char: char,        mode: FindRange,        smartcase: bool,    },    Sneak {        first_char: char,        second_char: char,        smartcase: bool,    },    SneakBackward {        first_char: char,        second_char: char,        smartcase: bool,    },    RepeatFind {        last_find: Box<Motion>,    },    RepeatFindReversed {        last_find: Box<Motion>,    },    NextLineStart,    PreviousLineStart,    StartOfLineDownward,    EndOfLineDownward,    GoToColumn,    WindowTop,    WindowMiddle,    WindowBottom,    NextSectionStart,    NextSectionEnd,    PreviousSectionStart,    PreviousSectionEnd,    NextMethodStart,    NextMethodEnd,    PreviousMethodStart,    PreviousMethodEnd,    NextComment,    PreviousComment,    PreviousLesserIndent,    PreviousGreaterIndent,    PreviousSameIndent,    NextLesserIndent,    NextGreaterIndent,    NextSameIndent,     // we don't have a good way to run a search synchronously, so    // we handle search motions by running the search async and then    // calling back into motion with this    ZedSearchResult {        prior_selections: Vec<Range<Anchor>>,        new_selections: Vec<Range<Anchor>>,    },    Jump {        anchor: Anchor,        line: bool,    },} #[derive(Clone, Copy)]enum IndentType {    Lesser,    Greater,    Same,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct NextWordStart {    #[serde(default)]    ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct NextWordEnd {    #[serde(default)]    ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct PreviousWordStart {    #[serde(default)]    ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct PreviousWordEnd {    #[serde(default)]    ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct NextSubwordStart {    #[serde(default)]    pub(crate) ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct NextSubwordEnd {    #[serde(default)]    pub(crate) ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct PreviousSubwordStart {    #[serde(default)]    pub(crate) ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct PreviousSubwordEnd {    #[serde(default)]    pub(crate) ignore_punctuation: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct Up {    #[serde(default)]    pub(crate) display_lines: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub(crate) struct Down {    #[serde(default)]    pub(crate) display_lines: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct FirstNonWhitespace {    #[serde(default)]    display_lines: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct EndOfLine {    #[serde(default)]    display_lines: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]pub struct StartOfLine {    #[serde(default)]    pub(crate) display_lines: bool,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct UnmatchedForward {    #[serde(default)]    char: char,} #[derive(Clone, Deserialize, JsonSchema, PartialEq)]#[serde(deny_unknown_fields)]struct UnmatchedBackward {    #[serde(default)]    char: char,} impl_actions!(    vim,    [        StartOfLine,        EndOfLine,        FirstNonWhitespace,        Down,        Up,        NextWordStart,        NextWordEnd,        PreviousWordStart,        PreviousWordEnd,        NextSubwordStart,        NextSubwordEnd,        PreviousSubwordStart,        PreviousSubwordEnd,        UnmatchedForward,        UnmatchedBackward    ]); actions!(    vim,    [        Left,        Backspace,        Right,        Space,        CurrentLine,        SentenceForward,        SentenceBackward,        StartOfParagraph,        EndOfParagraph,        StartOfDocument,        EndOfDocument,        Matching,        GoToPercentage,        NextLineStart,        PreviousLineStart,        StartOfLineDownward,        EndOfLineDownward,        GoToColumn,        RepeatFind,        RepeatFindReversed,        WindowTop,        WindowMiddle,        WindowBottom,        NextSectionStart,        NextSectionEnd,        PreviousSectionStart,        PreviousSectionEnd,        NextMethodStart,        NextMethodEnd,        PreviousMethodStart,        PreviousMethodEnd,        NextComment,        PreviousComment,        PreviousLesserIndent,        PreviousGreaterIndent,        PreviousSameIndent,        NextLesserIndent,        NextGreaterIndent,        NextSameIndent,    ]); action_with_deprecated_aliases!(vim, WrappingLeft, ["vim::Backspace"]);action_with_deprecated_aliases!(vim, WrappingRight, ["vim::Space"]); pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {    Vim::action(editor, cx, |vim, _: &Left, window, cx| {        vim.motion(Motion::Left, window, cx)    });    Vim::action(editor, cx, |vim, _: &WrappingLeft, window, cx| {        vim.motion(Motion::WrappingLeft, window, cx)    });    // Deprecated.    Vim::action(editor, cx, |vim, _: &Backspace, window, cx| {        vim.motion(Motion::WrappingLeft, window, cx)    });    Vim::action(editor, cx, |vim, action: &Down, window, cx| {        vim.motion(            Motion::Down {                display_lines: action.display_lines,            },            window,            cx,        )    });    Vim::action(editor, cx, |vim, action: &Up, window, cx| {        vim.motion(            Motion::Up {                display_lines: action.display_lines,            },            window,            cx,        )    });    Vim::action(editor, cx, |vim, _: &Right, window, cx| {        vim.motion(Motion::Right, window, cx)    });    Vim::action(editor, cx, |vim, _: &WrappingRight, window, cx| {        vim.motion(Motion::WrappingRight, window, cx)    });    // Deprecated.    Vim::action(editor, cx, |vim, _: &Space, window, cx| {        vim.motion(Motion::WrappingRight, window, cx)    });    Vim::action(        editor,        cx,        |vim, action: &FirstNonWhitespace, window, cx| {            vim.motion(                Motion::FirstNonWhitespace {                    display_lines: action.display_lines,                },                window,                cx,            )        },    );    Vim::action(editor, cx, |vim, action: &StartOfLine, window, cx| {        vim.motion(            Motion::StartOfLine {                display_lines: action.display_lines,            },            window,            cx,        )    });    Vim::action(editor, cx, |vim, action: &EndOfLine, window, cx| {        vim.motion(            Motion::EndOfLine {                display_lines: action.display_lines,            },            window,            cx,        )    });    Vim::action(editor, cx, |vim, _: &CurrentLine, window, cx| {        vim.motion(Motion::CurrentLine, window, cx)    });    Vim::action(editor, cx, |vim, _: &StartOfParagraph, window, cx| {        vim.motion(Motion::StartOfParagraph, window, cx)    });    Vim::action(editor, cx, |vim, _: &EndOfParagraph, window, cx| {        vim.motion(Motion::EndOfParagraph, window, cx)    });     Vim::action(editor, cx, |vim, _: &SentenceForward, window, cx| {        vim.motion(Motion::SentenceForward, window, cx)    });    Vim::action(editor, cx, |vim, _: &SentenceBackward, window, cx| {        vim.motion(Motion::SentenceBackward, window, cx)    });    Vim::action(editor, cx, |vim, _: &StartOfDocument, window, cx| {        vim.motion(Motion::StartOfDocument, window, cx)    });    Vim::action(editor, cx, |vim, _: &EndOfDocument, window, cx| {        vim.motion(Motion::EndOfDocument, window, cx)    });    Vim::action(editor, cx, |vim, _: &Matching, window, cx| {        vim.motion(Motion::Matching, window, cx)    });    Vim::action(editor, cx, |vim, _: &GoToPercentage, window, cx| {        vim.motion(Motion::GoToPercentage, window, cx)    });    Vim::action(        editor,        cx,        |vim, &UnmatchedForward { char }: &UnmatchedForward, window, cx| {            vim.motion(Motion::UnmatchedForward { char }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &UnmatchedBackward { char }: &UnmatchedBackward, window, cx| {            vim.motion(Motion::UnmatchedBackward { char }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &NextWordStart { ignore_punctuation }: &NextWordStart, window, cx| {            vim.motion(Motion::NextWordStart { ignore_punctuation }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &NextWordEnd { ignore_punctuation }: &NextWordEnd, window, cx| {            vim.motion(Motion::NextWordEnd { ignore_punctuation }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &PreviousWordStart { ignore_punctuation }: &PreviousWordStart, window, cx| {            vim.motion(Motion::PreviousWordStart { ignore_punctuation }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &PreviousWordEnd { ignore_punctuation }, window, cx| {            vim.motion(Motion::PreviousWordEnd { ignore_punctuation }, window, cx)        },    );    Vim::action(        editor,        cx,        |vim, &NextSubwordStart { ignore_punctuation }: &NextSubwordStart, window, cx| {            vim.motion(Motion::NextSubwordStart { ignore_punctuation }, window, cx)        },    );    Vim::action(        editor,        cx,

Lines 1–500 of 3819.