Improve local filetree view state and sidebar performance
This commit is contained in:
@@ -139,7 +139,12 @@ pub async fn update_options(
|
||||
)
|
||||
.with_context(context)
|
||||
})?;
|
||||
let (wired_options, ignored_options, warnings) = filter_wired_page_options(options);
|
||||
let (wired_options, ignored_options, warnings) =
|
||||
if input.effective_source_kind().as_deref() == Some("local_folder") {
|
||||
filter_local_ui_preference_options(options)
|
||||
} else {
|
||||
filter_wired_page_options(options)
|
||||
};
|
||||
page_command(
|
||||
state,
|
||||
context,
|
||||
@@ -235,7 +240,16 @@ async fn page_command(
|
||||
)
|
||||
.with_context(context)
|
||||
})?;
|
||||
crate::routes::update_local_page_options(&root_uri, &document_id, &options)?
|
||||
crate::routes::ui_preferences::update_page_preferences_from_value(
|
||||
state,
|
||||
context,
|
||||
context.auth.actor_id.trim(),
|
||||
workspace_id.as_deref().unwrap_or_default(),
|
||||
"local_folder",
|
||||
&root_uri,
|
||||
&document_id,
|
||||
&options,
|
||||
)?
|
||||
}
|
||||
_ => {
|
||||
return Err(WebError::bad_request_code(
|
||||
@@ -443,6 +457,41 @@ fn filter_wired_page_options(options: Value) -> (Value, Vec<String>, Vec<Value>)
|
||||
(Value::Object(out), ignored, warnings)
|
||||
}
|
||||
|
||||
fn filter_local_ui_preference_options(options: Value) -> (Value, Vec<String>, Vec<Value>) {
|
||||
let allowed = [
|
||||
"wideLayout",
|
||||
"smallText",
|
||||
"layoutDensity",
|
||||
"pageFont",
|
||||
"showHeadingNumbers",
|
||||
"showToc",
|
||||
"showStructure",
|
||||
"showWordCount",
|
||||
"collapseBacklinks",
|
||||
"hideChildPages",
|
||||
"showBlockRefCount",
|
||||
"hideTitleHeader",
|
||||
];
|
||||
let mut out = serde_json::Map::new();
|
||||
let mut ignored = Vec::new();
|
||||
let mut warnings = Vec::new();
|
||||
if let Value::Object(map) = options {
|
||||
for (key, value) in map {
|
||||
if allowed.contains(&key.as_str()) {
|
||||
out.insert(key, value);
|
||||
} else {
|
||||
warnings.push(json!({
|
||||
"code": "page_option_not_wired",
|
||||
"field": key.clone(),
|
||||
"message": "页面设置字段尚未接入 SQLite UI 偏好,已忽略"
|
||||
}));
|
||||
ignored.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
(Value::Object(out), ignored, warnings)
|
||||
}
|
||||
|
||||
fn summarize_blocks(content: &Value) -> Vec<Value> {
|
||||
let mut out = Vec::new();
|
||||
collect_blocks(content, &mut out);
|
||||
|
||||
Reference in New Issue
Block a user