diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java index 3b1ec674b..f0d153916 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileListComp.java @@ -136,40 +136,7 @@ public final class BrowserFileListComp extends SimpleComp { private void prepareTypedSelectionModel(TableView table) { AtomicReference lastFail = new AtomicReference<>(); table.addEventHandler(KeyEvent.KEY_PRESSED, event -> { - var typed = event.getText(); - if (typed.isEmpty()) { - return; - } - - var updated = typedSelection.get() + typed; - var found = fileList.getShown().getValue().stream() - .filter(browserEntry -> - browserEntry.getFileName().toLowerCase().startsWith(updated.toLowerCase())) - .findFirst(); - if (found.isEmpty()) { - if (lastFail.get() == null) { - lastFail.set(Instant.now()); - } - var inCooldown = Duration.between(lastFail.get(), Instant.now()).toMillis() < 1000; - if (inCooldown) { - lastFail.set(Instant.now()); - event.consume(); - return; - } else { - lastFail.set(null); - typedSelection.set(typed); - table.getSelectionModel().clearSelection(); - event.consume(); - return; - } - } - - lastFail.set(null); - typedSelection.set(updated); - table.scrollTo(found.get()); - table.getSelectionModel() - .clearAndSelect(fileList.getShown().getValue().indexOf(found.get())); - event.consume(); + updateTypedSelection(table, lastFail, event); }); table.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> { @@ -190,6 +157,43 @@ public final class BrowserFileListComp extends SimpleComp { }); } + private void updateTypedSelection(TableView table, AtomicReference lastType, KeyEvent event) { + var typed = event.getText(); + if (typed.isEmpty()) { + return; + } + + System.out.println(typedSelection.get() + " vs " + typed); + var updated = typedSelection.get() + typed; + var found = fileList.getShown().getValue().stream() + .filter(browserEntry -> + browserEntry.getFileName().toLowerCase().startsWith(updated.toLowerCase())) + .findFirst(); + if (found.isEmpty()) { + var inCooldown = lastType.get() != null && Duration.between(lastType.get(), Instant.now()).toMillis() < 1000; + if (inCooldown) { + System.out.println("cool"); + lastType.set(Instant.now()); + event.consume(); + return; + } else { + System.out.println("cancel"); + lastType.set(null); + typedSelection.set(""); + table.getSelectionModel().clearSelection(); + updateTypedSelection(table, lastType, event); + return; + } + } + + System.out.println("norm"); + lastType.set(Instant.now()); + typedSelection.set(updated); + table.scrollTo(found.get()); + table.getSelectionModel().clearAndSelect(fileList.getShown().getValue().indexOf(found.get())); + event.consume(); + } + private void prepareTableSelectionModel(TableView table) { if (!fileList.getSelectionMode().isMultiple()) { table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);