Skip to content

Commit

Permalink
search box
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Mar 23, 2022
1 parent ab817e4 commit 85dcd37
Show file tree
Hide file tree
Showing 22 changed files with 556 additions and 695 deletions.
4 changes: 4 additions & 0 deletions defaults/keymaps-macos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ command = "clipboard_copy"
key = "meta+v"
command = "clipboard_paste"

[[keymaps]]
key = "meta+f"
command = "search"

[[keymaps]]
key = "meta+right"
command = "word_forward"
Expand Down
4 changes: 4 additions & 0 deletions defaults/keymaps-nonmacos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ key = "ctrl+v"
command = "clipboard_paste"
mode = "i"

[[keymaps]]
key = "ctrl+f"
command = "search"

[[keymaps]]
key = "ctrl+right"
command = "word_forward"
Expand Down
3 changes: 3 additions & 0 deletions icons/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions lapce-data/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,51 @@ impl Buffer {
}
}

fn notify_special(&self) {
match &self.content {
BufferContent::File(_) => {}
BufferContent::Local(local) => {
let s = self.rope.to_string();
match local {
LocalBufferKind::Search => {
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSearch(s),
Target::Widget(self.tab_id),
);
}
LocalBufferKind::SourceControl => {}
LocalBufferKind::Empty => {}
LocalBufferKind::FilePicker => {
let pwd = PathBuf::from(s);
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdatePickerPwd(pwd),
Target::Widget(self.tab_id),
);
}
LocalBufferKind::Keymap => {
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateKeymapsFilter(s),
Target::Widget(self.tab_id),
);
}
LocalBufferKind::Settings => {
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSettingsFilter(s),
Target::Widget(self.tab_id),
);
}
}
}
BufferContent::Value(_) => {}
}

if let BufferContent::Local(LocalBufferKind::Search) = self.content {}
}

pub fn notify_update(&self, delta: Option<&RopeDelta>) {
self.trigger_syntax_change(delta);
self.trigger_history_change();
Expand Down Expand Up @@ -1785,6 +1830,7 @@ impl Buffer {
self.find.borrow_mut().unset();
*self.find_progress.borrow_mut() = FindProgress::Started;
self.notify_update(Some(delta));
self.notify_special();
}

pub fn update_edit_type(&mut self) {
Expand Down
4 changes: 4 additions & 0 deletions lapce-data/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ pub enum LapceCommand {
PreviousUnmatchedLeftCurlyBracket,
#[strum(serialize = "join_lines")]
JoinLines,
#[strum(serialize = "search")]
Search,
#[strum(serialize = "search_all")]
SelectAll,
#[strum(serialize = "search_whole_word_forward")]
SearchWholeWordForward,
#[strum(serialize = "search_forward")]
Expand Down
81 changes: 51 additions & 30 deletions lapce-data/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,15 +1992,15 @@ impl LapceMainSplitData {
let editor_tab =
Arc::make_mut(self.editor_tabs.get_mut(&active).unwrap());
match &editor_tab.children[editor_tab.active] {
EditorTabChild::Editor(id) => {
EditorTabChild::Editor(id, _) => {
if config.editor.show_tab {
if let Some(path) = path {
let mut editor_size = Size::ZERO;
for (i, child) in
editor_tab.children.iter().enumerate()
{
match child {
EditorTabChild::Editor(id) => {
EditorTabChild::Editor(id, _) => {
let editor =
self.editors.get(id).unwrap();
let current_size =
Expand Down Expand Up @@ -2038,20 +2038,20 @@ impl LapceMainSplitData {
config,
));
*new_editor.size.borrow_mut() = editor_size;
self.editors.insert(
new_editor.view_id,
new_editor.clone(),
);
editor_tab.children.insert(
editor_tab.active + 1,
EditorTabChild::Editor(new_editor.view_id),
EditorTabChild::Editor(
new_editor.view_id,
new_editor.find_view_id,
),
);
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::EditorTabAdd(
editor_tab.active + 1,
EditorTabChild::Editor(
new_editor.view_id,
new_editor.find_view_id,
),
),
Target::Widget(editor_tab.widget_id),
Expand All @@ -2062,6 +2062,7 @@ impl LapceMainSplitData {
LapceUICommand::Focus,
Target::Widget(new_editor.view_id),
));
self.insert_editor(new_editor.clone(), config);

return Arc::make_mut(
self.editors
Expand Down Expand Up @@ -2096,9 +2097,10 @@ impl LapceMainSplitData {
config,
));

editor_tab
.children
.push(EditorTabChild::Editor(editor.view_id));
editor_tab.children.push(EditorTabChild::Editor(
editor.view_id,
editor.find_view_id,
));

self.active = Arc::new(Some(editor.view_id));
self.active_tab = Arc::new(Some(editor_tab.widget_id));
Expand All @@ -2107,7 +2109,10 @@ impl LapceMainSplitData {
LAPCE_UI_COMMAND,
LapceUICommand::EditorTabAdd(
0,
EditorTabChild::Editor(editor.view_id),
EditorTabChild::Editor(
editor.view_id,
editor.find_view_id,
),
),
Target::Widget(editor_tab.widget_id),
));
Expand All @@ -2124,7 +2129,7 @@ impl LapceMainSplitData {
.children
.push(SplitContent::EditorTab(editor_tab.widget_id));

self.editors.insert(editor.view_id, editor.clone());
self.insert_editor(editor.clone(), config);
self.editor_tabs
.insert(editor_tab.widget_id, Arc::new(editor_tab));

Expand Down Expand Up @@ -2331,26 +2336,18 @@ impl LapceMainSplitData {
) -> Self {
let split_id = Arc::new(WidgetId::next());

let mut open_files = im::HashMap::new();
let open_files = im::HashMap::new();
let mut editors = im::HashMap::new();
let editor_tabs = im::HashMap::new();
let splits = im::HashMap::new();

let path = PathBuf::from("[Palette Preview Editor]");
let editor = LapceEditorData::new(
Some(palette_preview_editor),
None,
BufferContent::File(path.clone()),
BufferContent::Local(LocalBufferKind::Empty),
config,
);
editors.insert(editor.view_id, Arc::new(editor));
let mut buffer = Buffer::new(
BufferContent::File(path.clone()),
tab_id,
event_sink.clone(),
);
buffer.loaded = true;
open_files.insert(path, Arc::new(buffer));

let mut local_buffers = im::HashMap::new();
local_buffers.insert(
Expand Down Expand Up @@ -2423,6 +2420,20 @@ impl LapceMainSplitData {
main_split_data
}

pub fn insert_editor(&mut self, editor: Arc<LapceEditorData>, config: &Config) {
if let Some(find_view_id) = editor.find_view_id {
let find_editor = LapceEditorData::new(
Some(find_view_id),
None,
BufferContent::Local(LocalBufferKind::Search),
config,
);
self.editors
.insert(find_editor.view_id, Arc::new(find_editor));
}
self.editors.insert(editor.view_id, editor);
}

pub fn add_editor(
&mut self,
view_id: WidgetId,
Expand Down Expand Up @@ -2504,7 +2515,7 @@ impl LapceMainSplitData {
let editor_tab = self.editor_tabs.get(&tab_id).unwrap();
let mut index = 0;
for (i, child) in editor_tab.children.iter().enumerate() {
if child == &EditorTabChild::Editor(view_id) {
if child.widget_id() == view_id {
index = i;
}
}
Expand Down Expand Up @@ -2692,6 +2703,7 @@ impl LapceMainSplitData {
ctx: &mut EventCtx,
editor: &mut LapceEditorData,
direction: SplitDirection,
config: &Config,
) {
if let Some(editor_tab_id) = editor.tab_id {
let editor_tab = self.editor_tabs.get(&editor_tab_id).unwrap();
Expand All @@ -2701,7 +2713,10 @@ impl LapceMainSplitData {
widget_id: WidgetId::next(),
split: split_id,
active: 0,
children: vec![EditorTabChild::Editor(new_editor.view_id)],
children: vec![EditorTabChild::Editor(
new_editor.view_id,
new_editor.find_view_id,
)],
layout_rect: Rc::new(RefCell::new(Rect::ZERO)),
content_is_hot: Rc::new(RefCell::new(false)),
};
Expand All @@ -2724,8 +2739,7 @@ impl LapceMainSplitData {
editor_tab.split = new_split_id;
}

self.editors
.insert(new_editor.view_id, Arc::new(new_editor));
self.insert_editor(Arc::new(new_editor), config);
self.editor_tabs
.insert(new_editor_tab.widget_id, Arc::new(new_editor_tab));
}
Expand All @@ -2746,13 +2760,13 @@ pub enum InlineFindDirection {

#[derive(Clone, Debug, PartialEq)]
pub enum EditorTabChild {
Editor(WidgetId),
Editor(WidgetId, Option<WidgetId>),
}

impl EditorTabChild {
pub fn widget_id(&self) -> WidgetId {
match &self {
EditorTabChild::Editor(widget_id) => *widget_id,
EditorTabChild::Editor(widget_id, _) => *widget_id,
}
}

Expand All @@ -2762,7 +2776,7 @@ impl EditorTabChild {
tab_width: usize,
) -> EditorTabChildInfo {
match &self {
EditorTabChild::Editor(view_id) => {
EditorTabChild::Editor(view_id, _) => {
let editor_data = data.main_split.editors.get(view_id).unwrap();
EditorTabChildInfo::Editor(editor_data.editor_info(data, tab_width))
}
Expand All @@ -2771,7 +2785,7 @@ impl EditorTabChild {

pub fn set_editor_tab(&self, data: &mut LapceTabData, editor_tab_id: WidgetId) {
match &self {
EditorTabChild::Editor(view_id) => {
EditorTabChild::Editor(view_id, _) => {
let editor_data = data.main_split.editors.get_mut(view_id).unwrap();
let editor_data = Arc::make_mut(editor_data);
editor_data.tab_id = Some(editor_tab_id);
Expand Down Expand Up @@ -2816,6 +2830,7 @@ pub struct SelectionHistory {
pub struct LapceEditorData {
pub tab_id: Option<WidgetId>,
pub view_id: WidgetId,
pub find_view_id: Option<WidgetId>,
pub content: BufferContent,
pub compare: Option<String>,
pub code_lens: bool,
Expand All @@ -2842,6 +2857,11 @@ impl LapceEditorData {
Self {
tab_id,
view_id: view_id.unwrap_or_else(WidgetId::next),
find_view_id: if content.is_special() {
None
} else {
Some(WidgetId::next())
},
selection_history: SelectionHistory {
rev: 0,
content: content.clone(),
Expand Down Expand Up @@ -2870,6 +2890,7 @@ impl LapceEditorData {
pub fn copy(&self, new_view_id: WidgetId) -> LapceEditorData {
let mut new_editor = self.clone();
new_editor.view_id = new_view_id;
new_editor.find_view_id = new_editor.find_view_id.map(|_| WidgetId::next());
new_editor.size = Rc::new(RefCell::new(Size::ZERO));
new_editor
}
Expand Down
5 changes: 2 additions & 3 deletions lapce-data/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl EditorTabChildInfo {
config,
event_sink,
);
EditorTabChild::Editor(editor_data.view_id)
EditorTabChild::Editor(editor_data.view_id, editor_data.find_view_id)
}
}
}
Expand Down Expand Up @@ -285,8 +285,7 @@ impl EditorInfo {
data.open_files.insert(path.clone(), buffer);
}
}
data.editors
.insert(editor_data.view_id, Arc::new(editor_data.clone()));
data.insert_editor(Arc::new(editor_data.clone()), config);
editor_data
}
}
Expand Down
Loading

0 comments on commit 85dcd37

Please sign in to comment.