add settings value kind

This commit is contained in:
Dongdong Zhou 2022-05-31 11:05:02 +01:00
parent d519a0586e
commit 386ff068d5
6 changed files with 42 additions and 26 deletions

View File

@ -708,7 +708,7 @@ pub fn editor_view_content(
BufferContent::Local(kind) => {
self.main_split.local_docs.get(kind).unwrap().clone()
}
BufferContent::SettingsValue(name) => {
BufferContent::SettingsValue(name, _) => {
self.main_split.value_docs.get(name).unwrap().clone()
}
};
@ -737,7 +737,7 @@ pub fn code_action_size(&self, text: &mut PietText, _env: &Env) -> Size {
match &editor.content {
BufferContent::Local(_) => Size::ZERO,
BufferContent::SettingsValue(_) => Size::ZERO,
BufferContent::SettingsValue(_, _) => Size::ZERO,
BufferContent::File(path) => {
let doc = self.main_split.open_docs.get(path).unwrap();
let offset = editor.new_cursor.offset();
@ -792,7 +792,7 @@ pub fn update_from_editor_buffer_data(
.local_docs
.insert(kind.clone(), editor_buffer_data.doc);
}
BufferContent::SettingsValue(name) => {
BufferContent::SettingsValue(name, _) => {
self.main_split
.value_docs
.insert(name.clone(), editor_buffer_data.doc);
@ -820,7 +820,7 @@ pub fn completion_origin(
*editor.window_origin.borrow()
- self.window_origin.borrow().to_vec2()
}
BufferContent::SettingsValue(_) => {
BufferContent::SettingsValue(_, _) => {
*editor.window_origin.borrow()
- self.window_origin.borrow().to_vec2()
}
@ -876,7 +876,7 @@ pub fn hover_origin(
*editor.window_origin.borrow()
- self.window_origin.borrow().to_vec2()
}
BufferContent::SettingsValue(_) => {
BufferContent::SettingsValue(_, _) => {
*editor.window_origin.borrow()
- self.window_origin.borrow().to_vec2()
}
@ -1764,7 +1764,7 @@ pub fn content_doc(&self, content: &BufferContent) -> Arc<Document> {
match content {
BufferContent::File(path) => self.open_docs.get(path).unwrap().clone(),
BufferContent::Local(kind) => self.local_docs.get(kind).unwrap().clone(),
BufferContent::SettingsValue(name) => {
BufferContent::SettingsValue(name, _) => {
self.value_docs.get(name).unwrap().clone()
}
BufferContent::Scratch(id, _) => {
@ -2314,7 +2314,7 @@ pub fn go_to_location(
let new_buffer = match doc.content() {
BufferContent::File(path) => path != &location.path,
BufferContent::Local(_) => true,
BufferContent::SettingsValue(_) => true,
BufferContent::SettingsValue(_, _) => true,
BufferContent::Scratch(..) => true,
};
if new_buffer {

View File

@ -43,6 +43,7 @@
find::{Find, FindProgress},
history::DocumentHisotry,
proxy::LapceProxy,
settings::SettingsValueKind,
};
pub struct SystemClipboard {}
@ -98,7 +99,7 @@ pub enum LocalBufferKind {
pub enum BufferContent {
File(PathBuf),
Local(LocalBufferKind),
SettingsValue(String),
SettingsValue(String, SettingsValueKind),
Scratch(BufferId, String),
}
@ -119,7 +120,7 @@ pub fn is_special(&self) -> bool {
| LocalBufferKind::Keymap => true,
LocalBufferKind::Empty => false,
},
BufferContent::SettingsValue(_) => true,
BufferContent::SettingsValue(_, _) => true,
BufferContent::Scratch(..) => false,
}
}
@ -135,7 +136,7 @@ pub fn is_input(&self) -> bool {
| LocalBufferKind::Keymap => true,
LocalBufferKind::Empty | LocalBufferKind::SourceControl => false,
},
BufferContent::SettingsValue(_) => true,
BufferContent::SettingsValue(_, _) => true,
BufferContent::Scratch(..) => false,
}
}
@ -143,7 +144,7 @@ pub fn is_input(&self) -> bool {
pub fn is_search(&self) -> bool {
match &self {
BufferContent::File(_) => false,
BufferContent::SettingsValue(_) => false,
BufferContent::SettingsValue(_, _) => false,
BufferContent::Scratch(..) => false,
BufferContent::Local(local) => matches!(local, LocalBufferKind::Search),
}
@ -152,7 +153,7 @@ pub fn is_search(&self) -> bool {
pub fn is_settings(&self) -> bool {
match &self {
BufferContent::File(_) => false,
BufferContent::SettingsValue(_) => true,
BufferContent::SettingsValue(_, _) => true,
BufferContent::Local(_) => false,
BufferContent::Scratch(..) => false,
}
@ -201,7 +202,7 @@ pub fn new(
let syntax = match &content {
BufferContent::File(path) => Syntax::init(path),
BufferContent::Local(_) => None,
BufferContent::SettingsValue(_) => None,
BufferContent::SettingsValue(_, _) => None,
BufferContent::Scratch(..) => None,
};
let id = match &content {
@ -244,7 +245,7 @@ pub fn set_content(&mut self, content: BufferContent) {
self.syntax = match &self.content {
BufferContent::File(path) => Syntax::init(path),
BufferContent::Local(_) => None,
BufferContent::SettingsValue(_) => None,
BufferContent::SettingsValue(_, _) => None,
BufferContent::Scratch(..) => None,
};
self.on_update(None);
@ -517,7 +518,7 @@ fn notify_special(&self) {
}
}
}
BufferContent::SettingsValue(_) => {}
BufferContent::SettingsValue(_, _) => {}
}
}

View File

@ -1947,7 +1947,7 @@ fn check_condition(&self, condition: &str) -> bool {
BufferContent::File(_) => true,
BufferContent::Scratch(..) => true,
BufferContent::Local(_) => false,
BufferContent::SettingsValue(_) => false,
BufferContent::SettingsValue(_, _) => false,
},
"diff_focus" => self.editor.compare.is_some(),
"source_control_focus" => {

View File

@ -3,6 +3,7 @@
command::{EditCommand, FocusCommand, MoveCommand},
mode::Mode,
};
use serde::{Deserialize, Serialize};
use crate::{
command::{CommandExecuted, CommandKind, LapceUICommand, LAPCE_UI_COMMAND},
@ -11,6 +12,13 @@
split::SplitDirection,
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum SettingsValueKind {
String,
Number,
Bool,
}
pub enum LapceSettingsKind {
Core,
Editor,

View File

@ -157,7 +157,7 @@ pub fn request_focus(
data.main_split.active_tab = Arc::new(editor.tab_id);
}
},
BufferContent::SettingsValue(_) => {}
BufferContent::SettingsValue(_, _) => {}
}
}
@ -556,7 +556,7 @@ fn event(
}
Event::Timer(id) if self.last_idle_timer == *id => {
ctx.set_handled();
if let BufferContent::SettingsValue(name) =
if let BufferContent::SettingsValue(name, _) =
&editor_data.editor.content
{
// ctx.submit_command(Command::new(
@ -709,7 +709,7 @@ fn update(
let old_editor_data = old_data.editor_view_content(self.view_id);
let editor_data = data.editor_view_content(self.view_id);
if let BufferContent::SettingsValue(_) = &editor_data.editor.content {
if let BufferContent::SettingsValue(_, _) = &editor_data.editor.content {
if editor_data.doc.buffer().len() != old_editor_data.doc.buffer().len()
|| editor_data.doc.buffer().text().slice_to_cow(..)
!= old_editor_data.doc.buffer().text().slice_to_cow(..)

View File

@ -25,7 +25,7 @@
data::{LapceEditorData, LapceTabData},
document::{BufferContent, Document},
keypress::KeyPressFocus,
settings::LapceSettingsFocusData,
settings::{LapceSettingsFocusData, SettingsValueKind},
};
use xi_rope::Rope;
@ -549,16 +549,20 @@ pub fn new(
event_sink: ExtEventSink,
) -> Self {
let input = match &value {
serde_json::Value::Number(n) => Some(n.to_string()),
serde_json::Value::String(s) => Some(s.to_string()),
serde_json::Value::Number(n) => {
Some((n.to_string(), SettingsValueKind::Number))
}
serde_json::Value::String(s) => {
Some((s.to_string(), SettingsValueKind::String))
}
serde_json::Value::Array(_)
| serde_json::Value::Object(_)
| serde_json::Value::Bool(_)
| serde_json::Value::Null => None,
};
let input = input.map(|input| {
let input = input.map(|(input, value_kind)| {
let name = format!("{kind}.{name}");
let content = BufferContent::SettingsValue(name.clone());
let content = BufferContent::SettingsValue(name.clone(), value_kind);
let mut doc = Document::new(
content.clone(),
@ -895,7 +899,7 @@ fn update(
}
if let Some(view_id) = self.input_view_id.as_ref() {
let editor = data.main_split.editors.get(view_id).unwrap();
if let BufferContent::SettingsValue(name) = &editor.content {
if let BufferContent::SettingsValue(name, _) = &editor.content {
let doc = data.main_split.value_docs.get(name).unwrap();
let old_doc = old_data.main_split.value_docs.get(name).unwrap();
if doc.buffer().len() != old_doc.buffer().len()
@ -1057,7 +1061,10 @@ fn update_inputs(&mut self, ctx: &mut EventCtx, data: &mut LapceTabData) {
for color in colors {
let name = format!("lapce.color.{color}");
let content = BufferContent::SettingsValue(name.clone());
let content = BufferContent::SettingsValue(
name.clone(),
SettingsValueKind::String,
);
let mut doc = Document::new(
content.clone(),
data.id,