Skip to content

Commit 9bc5c7a

Browse files
committed
live-preview: Sort selection popup by area of elements
This is an alternate mode in the selection popup, click on the button next to the search bar to activate.
1 parent 4d309f6 commit 9bc5c7a

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

REUSE.toml

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ SPDX-License-Identifier = "LicenseRef-qskinny"
158158
path = [
159159
"tools/lsp/ui/assets/chevron-down.svg",
160160
"tools/lsp/ui/assets/inspect.svg",
161+
"tools/lsp/ui/assets/list-filter.svg",
161162
"tools/lsp/ui/assets/layout-sidebar**.svg",
162163
"tools/lsp/ui/assets/search.svg",
163164
"tools/lsp/ui/assets/sync.svg",

tools/lsp/preview/element_selection.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,23 @@ pub fn selection_stack_at(
447447
pub fn filter_sort_selection_stack(
448448
model: slint::ModelRc<crate::preview::ui::SelectionStackFrame>,
449449
filter: slint::SharedString,
450+
sort_by_area: bool,
450451
) -> slint::ModelRc<crate::preview::ui::SelectionStackFrame> {
451452
use slint::ModelExt;
452453

453-
eprintln!("filter: {filter}");
454+
eprintln!("filter: {filter}: {sort_by_area}");
455+
456+
let model = if sort_by_area {
457+
Rc::new(model.sort_by(|a, b| {
458+
let a_area = a.width * a.height;
459+
let b_area = b.width * b.height;
460+
461+
a_area.partial_cmp(&b_area).unwrap_or(std::cmp::Ordering::Equal)
462+
}))
463+
.into()
464+
} else {
465+
model
466+
};
454467

455468
let filter = filter.to_string();
456469

tools/lsp/ui/api.slint

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export global Api {
404404

405405
// ## Element selection:
406406
callback selection-stack-at(x: length, y: length) -> [SelectionStackFrame];
407-
pure callback filter-sort-selection-stack(model: [SelectionStackFrame], filter: string) -> [SelectionStackFrame];
407+
pure callback filter-sort-selection-stack(model: [SelectionStackFrame], filter: string, sort-by-area: bool) -> [SelectionStackFrame];
408408
pure callback find-selected-selection-stack-frame([SelectionStackFrame]) -> SelectionStackFrame;
409409
callback select-element(file: string, offset: int, x: length, y: length);
410410

tools/lsp/ui/assets/list-filter.svg

+1
Loading

tools/lsp/ui/components/selection-popup.slint

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright © SixtyFPS GmbH <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
import { ListView, Palette, ScrollView, LineEdit } from "std-widgets.slint";
4+
import { ListView, Palette, ScrollView, LineEdit, Button } from "std-widgets.slint";
55
import { EditorFontSettings, EditorSizeSettings, EditorSpaceSettings, EditorPalette } from "./styling.slint";
66
import { Api, SelectionStackFrame } from "../api.slint";
77
import { Icons } from "styling.slint";
@@ -165,14 +165,20 @@ component PopupInner inherits Rectangle {
165165
self.focus();
166166
}
167167
}
168+
169+
sort-by-area-button := Button {
170+
checkable: true;
171+
icon: Icons.list-filter;
172+
colorize-icon: true;
173+
}
168174
}
169175

170176
ScrollView {
171177
height: (root.visible-frames * root.frame-height);
172178

173179
list-view := VerticalLayout {
174180

175-
for frame[index] in Api.filter-sort-selection-stack(root.selection-stack, filter-edit.text): frame-rect := Rectangle {
181+
for frame[index] in Api.filter-sort-selection-stack(root.selection-stack, filter-edit.text, sort-by-area-button.checked): frame-rect := Rectangle {
176182
height: root.frame-height;
177183

178184
function frame-color(frame: SelectionStackFrame) -> brush {

tools/lsp/ui/components/styling.slint

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Palette } from "std-widgets.slint";
66
export global Icons {
77
out property <image> add: @image-url("../assets/add.svg");
88
out property <image> chevron-down: @image-url("../assets/chevron-down.svg");
9+
out property <image> list-filter: @image-url("../assets/list-filter.svg");
910
out property <image> inspect: @image-url("../assets/inspect.svg");
1011
out property <image> search: @image-url("../assets/search.svg");
1112
out property <image> sidebar-left-off: @image-url("../assets/layout-sidebar-left-off.svg");

0 commit comments

Comments
 (0)