opt: jump to selected item
This commit is contained in:
parent
7a938ace02
commit
03af5042ec
@ -228,8 +228,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
onDragExited: (exit) {
|
onDragExited: (exit) {
|
||||||
_dropMaskVisible.value = false;
|
_dropMaskVisible.value = false;
|
||||||
},
|
},
|
||||||
child:
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
||||||
headTools(isLocal),
|
headTools(isLocal),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -270,7 +269,6 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
|
|
||||||
return MouseRegion(
|
return MouseRegion(
|
||||||
onEnter: (evt) {
|
onEnter: (evt) {
|
||||||
print("enter $evt");
|
|
||||||
_mouseFocusScope.value =
|
_mouseFocusScope.value =
|
||||||
isLocal ? MouseFocusScope.local : MouseFocusScope.remote;
|
isLocal ? MouseFocusScope.local : MouseFocusScope.remote;
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
@ -280,9 +278,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onExit: (evt) {
|
onExit: (evt) {
|
||||||
print("exit $evt");
|
|
||||||
_mouseFocusScope.value = MouseFocusScope.none;
|
_mouseFocusScope.value = MouseFocusScope.none;
|
||||||
// FocusManager.instance.primaryFocus?.unfocus();
|
|
||||||
},
|
},
|
||||||
child: ListSearchActionListener(
|
child: ListSearchActionListener(
|
||||||
node: isLocal ? _keyboardNodeLocal : _keyboardNodeRemote,
|
node: isLocal ? _keyboardNodeLocal : _keyboardNodeRemote,
|
||||||
@ -304,19 +300,18 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
.skip(skipCount)
|
.skip(skipCount)
|
||||||
.where((element) => element.name.startsWith(buffer));
|
.where((element) => element.name.startsWith(buffer));
|
||||||
if (searchResult.isEmpty) {
|
if (searchResult.isEmpty) {
|
||||||
// loop
|
// cannot find next, lets restart search from head
|
||||||
searchResult =
|
searchResult =
|
||||||
entries.where((element) => element.name.startsWith(buffer));
|
entries.where((element) => element.name.startsWith(buffer));
|
||||||
}
|
}
|
||||||
if (searchResult.isEmpty) {
|
if (searchResult.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
getSelectedItems(isLocal).clear();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final offset = entries.indexOf(searchResult.first) * rowHeight;
|
_jumpToEntry(
|
||||||
setState(() {
|
isLocal, searchResult.first, scrollController, rowHeight, buffer);
|
||||||
selectedEntries.clear();
|
|
||||||
selectedEntries.add(isLocal, searchResult.first);
|
|
||||||
debugPrint("focused on ${searchResult.first.name}");
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
onSearch: (buffer) {
|
onSearch: (buffer) {
|
||||||
debugPrint("searching for $buffer");
|
debugPrint("searching for $buffer");
|
||||||
@ -325,12 +320,13 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
entries.where((element) => element.name.startsWith(buffer));
|
entries.where((element) => element.name.startsWith(buffer));
|
||||||
selectedEntries.clear();
|
selectedEntries.clear();
|
||||||
if (searchResult.isEmpty) {
|
if (searchResult.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
getSelectedItems(isLocal).clear();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
_jumpToEntry(
|
||||||
selectedEntries.add(isLocal, searchResult.first);
|
isLocal, searchResult.first, scrollController, rowHeight, buffer);
|
||||||
debugPrint("focused on ${searchResult.first.name}");
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
child: ObxValue<RxString>(
|
child: ObxValue<RxString>(
|
||||||
(searchText) {
|
(searchText) {
|
||||||
@ -446,8 +442,8 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
child: Text(
|
child: Text(
|
||||||
sizeStr,
|
sizeStr,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style:
|
style: TextStyle(
|
||||||
TextStyle(fontSize: 10, color: MyTheme.darkGray),
|
fontSize: 10, color: MyTheme.darkGray),
|
||||||
))),
|
))),
|
||||||
]);
|
]);
|
||||||
}).toList(growable: false),
|
}).toList(growable: false),
|
||||||
@ -459,6 +455,31 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _jumpToEntry(bool isLocal, Entry entry,
|
||||||
|
ScrollController scrollController, double rowHeight, String buffer) {
|
||||||
|
final entries = model.getCurrentDir(isLocal).entries;
|
||||||
|
final index = entries.indexOf(entry);
|
||||||
|
if (index == -1) {
|
||||||
|
debugPrint("entry is not valid: ${entry.path}");
|
||||||
|
}
|
||||||
|
final selectedEntries = getSelectedItems(isLocal);
|
||||||
|
final searchResult =
|
||||||
|
entries.where((element) => element.name.startsWith(buffer));
|
||||||
|
selectedEntries.clear();
|
||||||
|
if (searchResult.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final offset = min(
|
||||||
|
max(scrollController.position.minScrollExtent,
|
||||||
|
entries.indexOf(searchResult.first) * rowHeight),
|
||||||
|
scrollController.position.maxScrollExtent);
|
||||||
|
scrollController.jumpTo(offset);
|
||||||
|
setState(() {
|
||||||
|
selectedEntries.add(isLocal, searchResult.first);
|
||||||
|
debugPrint("focused on ${searchResult.first.name}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _onSelectedChanged(SelectedItems selectedItems, List<Entry> entries,
|
void _onSelectedChanged(SelectedItems selectedItems, List<Entry> entries,
|
||||||
Entry entry, bool isLocal) {
|
Entry entry, bool isLocal) {
|
||||||
final isCtrlDown = RawKeyboard.instance.keysPressed
|
final isCtrlDown = RawKeyboard.instance.keysPressed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user