Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apple/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apple/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let package = Package(
.library(name: "LogseqChatModel", type: .dynamic, targets: ["LogseqChatModel"]),
],
dependencies: [
.package(url: "ssh://git@github.com/logseq/lui.git", revision: "d2b3b07"),
.package(url: "ssh://git@github.com/logseq/lui.git", revision: "55166025"),
.package(url: "https://github.com/gonzalezreal/swiftui-math", from: "0.1.0"),
.package(url: "https://github.com/appstefan/highlightswift.git", from: "1.1.0")
],
Expand Down
4 changes: 4 additions & 0 deletions apple/Sources/LogseqChat/LGChatRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ enum LGChatIconPolicy {
"toolbar-delete": .systemName("trash"),
"toolbar-hide-keyboard": .assetName("toolbar_hide_keyboard"),
"toolbar-indent": .assetName("toolbar_indent"),
"toolbar-move-down": .systemName("arrow.down"),
"toolbar-move-up": .systemName("arrow.up"),
"toolbar-outdent": .assetName("toolbar_outdent"),
"toolbar-tag": .assetName("toolbar_tag"),
"toolbar-task": .assetName("task_done"),
Expand All @@ -109,6 +111,8 @@ enum LGChatIconPolicy {
result["toolbar-camera"] = .systemName("camera")
result["toolbar-hide-keyboard"] = .systemName("keyboard.chevron.compact.down")
result["toolbar-indent"] = .systemName("arrow.right")
result["toolbar-move-down"] = .systemName("arrow.down")
result["toolbar-move-up"] = .systemName("arrow.up")
result["toolbar-outdent"] = .systemName("arrow.left")
result["toolbar-tag"] = .systemName("number")
result["toolbar-task"] = .systemName("checkmark.square")
Expand Down
2 changes: 2 additions & 0 deletions flutter/lib/logseq_chat_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const logseqChatAppIcons = <String, IconData>{
'toolbar-delete': Icons.delete_outline_rounded,
'toolbar-hide-keyboard': Icons.keyboard_hide_rounded,
'toolbar-indent': Icons.format_indent_increase,
'toolbar-move-down': Icons.arrow_downward_rounded,
'toolbar-move-up': Icons.arrow_upward_rounded,
'toolbar-outdent': Icons.format_indent_decrease,
'toolbar-tag': Icons.tag_rounded,
'toolbar-task': Icons.check_box_outlined,
Expand Down
4 changes: 2 additions & 2 deletions flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ packages:
dependency: "direct main"
description:
path: "platform/flutter"
ref: d2b3b0739bf047a1df5d22d3f316a45e430a68bd
resolved-ref: d2b3b0739bf047a1df5d22d3f316a45e430a68bd
ref: 5516602566127dd437c4d2ad9d1700c474b76970
resolved-ref: 5516602566127dd437c4d2ad9d1700c474b76970
url: "ssh://git@github.com/logseq/lui.git"
source: git
version: "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
lui_flutter_backend:
git:
url: ssh://git@github.com/logseq/lui.git
ref: d2b3b0739bf047a1df5d22d3f316a45e430a68bd
ref: 5516602566127dd437c4d2ad9d1700c474b76970
path: platform/flutter
webview_flutter: ^4.14.1

Expand Down
133 changes: 123 additions & 10 deletions shared/src/logseq_chat/core/outliner_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type outliner_toolbar =
| Task
| Outdent
| Indent
| Move_up
| Move_down
| Tag_action
| Page_reference
| Camera
Expand Down Expand Up @@ -804,22 +806,46 @@ let outdent (context : outliner_context) selected =
|> (fun parent ->
match parent with
| Some (parent : Model.block) ->
if
selection_is_contiguous roots
(sorted_siblings context (Some parent.uuid))
then
let siblings = sorted_siblings context (Some parent.uuid) in
if selection_is_contiguous roots siblings then
let parent_uuid =
match parent.parent_id with
| Some uuid -> uuid
| None -> parent.page_id
in
let siblings = sorted_siblings context (Some parent_uuid) in
(match index_of_uuid parent.uuid siblings with
let parent_row = sorted_siblings context (Some parent_uuid) in
(match index_of_uuid parent.uuid parent_row with
| Some index ->
moves_with_orders roots parent_uuid parent.order
(if index + 1 < List.length siblings then
(List.nth siblings (index + 1)).order
else None)
(match
moves_with_orders roots parent_uuid parent.order
(if index + 1 < List.length parent_row then
(List.nth parent_row (index + 1)).order
else None)
with
| Some moves ->
(* logseq direct outdenting: the trailing siblings of the
last moved block become its children *)
let last_index =
List.fold_left max 0 (selection_indices roots siblings)
in
let last = List.nth siblings last_index in
let trailing =
List.filteri (fun i _ -> i > last_index) siblings
in
(match trailing with
| [] -> Some moves
| trailing ->
let lower =
match
List.rev (sorted_siblings context (Some last.uuid))
with
| child :: _ -> child.order
| [] -> None
in
(match moves_with_orders trailing last.uuid lower None with
| Some adopted -> Some (moves @ adopted)
| None -> Some moves))
| None -> None)
| None -> None)
else None
| None -> None)
Expand Down Expand Up @@ -1013,6 +1039,86 @@ let toolbar_insert (state : outliner_state) text backward =
[ Haptic Impact ]
| None -> step state []

let move (context : outliner_context) selected up_ =
let roots = selected_roots context selected in
match roots with
| [] -> None
| first :: _ ->
if not (same_parent roots (first : Model.block).parent_id) then None
else
let parent =
match first.parent_id with Some uuid -> uuid | None -> first.page_id
in
let siblings = sorted_siblings context (Some parent) in
(match selection_indices roots siblings with
| [] -> None
| first_index :: _ as indices ->
if not (selection_is_contiguous roots siblings) then None
else
let last_index = first_index + List.length indices - 1 in
(* like logseq's move-blocks-up-down: at a boundary the selection
crosses into the parent's neighbor as its first child *)
let parent_neighbor before =
if parent = first.page_id then None
else
match find_block context parent with
| Some parent_block ->
let grandparent =
match (parent_block : Model.block).parent_id with
| Some uuid -> uuid
| None -> parent_block.page_id
in
let parent_siblings =
sorted_siblings context (Some grandparent)
in
(match index_of_uuid parent_block.uuid parent_siblings with
| Some index ->
let neighbor_index =
if before then index - 1 else index + 1
in
if
neighbor_index < 0
|| neighbor_index >= List.length parent_siblings
then None
else Some (List.nth parent_siblings neighbor_index)
| None -> None)
| None -> None
in
let first_child_order (block : Model.block) =
match sorted_siblings context (Some block.uuid) with
| child :: _ -> child.order
| [] -> None
in
if up_ then
if first_index = 0 then
match parent_neighbor true with
| Some neighbor ->
moves_with_orders roots neighbor.uuid None
(first_child_order neighbor)
| None -> None
else
let target = List.nth siblings (first_index - 1) in
let lower =
if first_index > 1 then
(List.nth siblings (first_index - 2)).order
else None
in
moves_with_orders roots parent lower target.order
else if last_index + 1 >= List.length siblings then
match parent_neighbor false with
| Some neighbor ->
moves_with_orders roots neighbor.uuid None
(first_child_order neighbor)
| None -> None
else
let target = List.nth siblings (last_index + 1) in
let upper =
if last_index + 2 < List.length siblings then
(List.nth siblings (last_index + 2)).order
else None
in
moves_with_orders roots parent target.order upper)

let toolbar_move context (state : outliner_state) outdent_ =
let moves =
if outdent_ then outdent context (interaction_targets state)
Expand All @@ -1023,6 +1129,11 @@ let toolbar_move context (state : outliner_state) outdent_ =
| Some moves -> [ Reparent_blocks moves; Haptic Impact ]
| None -> [ Haptic Impact ])

let toolbar_reorder context (state : outliner_state) up_ =
match move context (interaction_targets state) up_ with
| Some moves -> step state [ Reparent_blocks moves; Haptic Impact ]
| None -> step state [ Haptic Impact ]

let choose_completion context (state : outliner_state) value =
match (state.editing, state.autocomplete) with
| Some editing, Some request ->
Expand Down Expand Up @@ -1172,6 +1283,8 @@ let update context (state : outliner_state) message =
| None -> step state [])
| Toolbar Indent -> toolbar_move context state false
| Toolbar Outdent -> toolbar_move context state true
| Toolbar Move_up -> toolbar_reorder context state true
| Toolbar Move_down -> toolbar_reorder context state false
| Toolbar Delete ->
let uuids = selected_uuids state in
step
Expand Down
12 changes: 12 additions & 0 deletions shared/src/logseq_chat/core/outliner_state.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type outliner_toolbar =
| Task
| Outdent
| Indent
| Move_up
| Move_down
| Tag_action
| Page_reference
| Camera
Expand Down Expand Up @@ -222,6 +224,11 @@ val selection_is_contiguous :
val same_parent : Cache_model.block list -> string option -> bool
val indent : outliner_context -> Sset.t -> Pending_ops.pending_move list option
val outdent : outliner_context -> Sset.t -> Pending_ops.pending_move list option
val move :
outliner_context ->
Sset.t ->
bool ->
Pending_ops.pending_move list option
val ancestor_uuids : outliner_context -> Cache_model.block -> Sset.t
val drop :
outliner_context ->
Expand Down Expand Up @@ -253,6 +260,11 @@ val toolbar_move :
outliner_state ->
bool ->
outliner_state * outliner_command list
val toolbar_reorder :
outliner_context ->
outliner_state ->
bool ->
outliner_state * outliner_command list
val choose_completion :
outliner_context ->
outliner_state ->
Expand Down
2 changes: 2 additions & 0 deletions shared/src/logseq_chat/core/rpc_wire.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ let toolbar_action wire =
| "task" -> Ok Outliner.Task
| "outdent" -> Ok Outliner.Outdent
| "indent" -> Ok Outliner.Indent
| "moveUp" -> Ok Outliner.Move_up
| "moveDown" -> Ok Outliner.Move_down
| "tag" -> Ok Outliner.Tag_action
| "pageReference" -> Ok Outliner.Page_reference
| "camera" -> Ok Outliner.Camera
Expand Down
8 changes: 8 additions & 0 deletions shared/src/logseq_chat/view_outliner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ let outliner_editor_toolbar (context : Lui_ui.ui_context) model_source send
"button.outliner.editor.outdent" "outdent" send;
toolbar_button (`app "toolbar-indent") "Indent"
"button.outliner.editor.indent" "indent" send;
toolbar_button (`app "toolbar-move-up") "Move up"
"button.outliner.editor.moveUp" "moveUp" send;
toolbar_button (`app "toolbar-move-down") "Move down"
"button.outliner.editor.moveDown" "moveDown" send;
toolbar_button (`app "toolbar-tag") "Tag"
"button.outliner.editor.tag" "tag" send;
toolbar_button (`app "toolbar-camera") "Photo"
Expand Down Expand Up @@ -730,6 +734,10 @@ let outliner_editor_toolbar (context : Lui_ui.ui_context) model_source send
"button.outliner.editor.outdent" "outdent";
apple_icon_button (`app "toolbar-indent") "Indent"
"button.outliner.editor.indent" "indent";
apple_icon_button (`app "toolbar-move-up") "Move up"
"button.outliner.editor.moveUp" "moveUp";
apple_icon_button (`app "toolbar-move-down") "Move down"
"button.outliner.editor.moveDown" "moveDown";
apple_icon_button (`app "toolbar-tag") "Tag"
"button.outliner.editor.tag" "tag";
apple_icon_button (`app "toolbar-camera") "Photo"
Expand Down
16 changes: 9 additions & 7 deletions shared/test/logseq_chat/app_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7676,7 +7676,7 @@ let flutter_outliner_editor_toolbar_uses_a_material_bottom_surface () =
(property_string renderer editor_container Lui_protocol.BackgroundValue)
"surface-container-low";
check_eq ~msg:"all editor actions remain reachable by horizontal scroll"
(List.length buttons) 9;
(List.length buttons) 11;
List.iter
(fun button ->
check_eq ~msg:"every editor action has a 48dp target"
Expand All @@ -7689,7 +7689,7 @@ let flutter_outliner_editor_toolbar_uses_a_material_bottom_surface () =
(property_string renderer button Lui_protocol.SizeValue)
"icon")
buttons;
let page_reference = List.nth buttons 7 in
let page_reference = List.nth buttons 9 in
check_eq ~msg:"page reference does not use an unrelated code glyph"
(property_string renderer page_reference Lui_protocol.InlineIconName)
"<missing>";
Expand Down Expand Up @@ -7831,16 +7831,18 @@ let outliner_editor_toolbar_and_autocomplete_use_core_owned_state () =
(0, "app:toolbar-task");
(1, "app:toolbar-outdent");
(2, "app:toolbar-indent");
(3, "app:toolbar-tag");
(4, "app:toolbar-camera");
(5, "app:toolbar-audio");
(3, "app:toolbar-move-up");
(4, "app:toolbar-move-down");
(5, "app:toolbar-tag");
(6, "app:toolbar-camera");
(7, "app:toolbar-audio");
];
check_eq ~msg:"the iOS editor toolbar omits the file picker"
(descendant_with_identifier renderer editor_toolbar
"button.outliner.editor.attachment")
(-1);
let page_reference_button = List.nth editor_buttons 6 in
let hide_keyboard_button = List.nth editor_buttons 7 in
let page_reference_button = List.nth editor_buttons 8 in
let hide_keyboard_button = List.nth editor_buttons 9 in
check_eq ~msg:"page reference retains main's compact symbolic label"
(property_string renderer page_reference_button Lui_protocol.TextValue)
"[[]]";
Expand Down
Loading
Loading