search and select from search working.scroll in search window not yet working

This commit is contained in:
Iaphetes 2025-02-01 13:16:08 +01:00
parent c87cf5c8ee
commit 95867768c4
3 changed files with 41 additions and 7 deletions

View file

@ -1,5 +1,6 @@
const { convertFileSrc, invoke } = window.__TAURI__.core; const { convertFileSrc, invoke } = window.__TAURI__.core;
import { handle_file_select } from "./filesystem.js";
var search_input = document.getElementById("file-search-dialog-input"); var search_input = document.getElementById("file-search-dialog-input");
search_input.addEventListener('input', () => { search_input.addEventListener('input', () => {
search_files(); search_files();
@ -17,8 +18,31 @@ function search_files(){
result_div += element; result_div += element;
}); });
console.log(result_div); console.log(result_div);
tag_id.innerHTML = "<pre>".concat("", result_div).concat("", "</pre>"); tag_id.innerHTML = result_div;
// tag_id.innerHTML = assetUrl.concat(" ", ' \n <img src="'.concat("", assetUrl).concat("", '" alt="Girl in a jacket" width="500" height="600">')) // tag_id.innerHTML = assetUrl.concat(" ", ' \n <img src="'.concat("", assetUrl).concat("", '" alt="Girl in a jacket" width="500" height="600">'))
} }
); );
} }
let filetree = document.getElementById('file-search-results');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = (mutationList, observer) => {
console.log("updating on click");
var anchors = document.getElementsByClassName("file-search-button");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
anchor.onclick = function() {
handle_file_select(this.parentElement.id);
};
};
};
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(filetree, config);

View file

@ -1,7 +1,7 @@
const { convertFileSrc, invoke } = window.__TAURI__.core; const { convertFileSrc, invoke } = window.__TAURI__.core;
const { readTextFile } = window.__TAURI__.fs; const { readTextFile } = window.__TAURI__.fs;
import { render_markdown } from "./main.js"; import { render_markdown } from "./main.js";
function handle_file_select(filename) { export function handle_file_select(filename) {
if (filename.endsWith("md")) { if (filename.endsWith("md")) {
readTextFile(convertFileSrc(filename)).then( readTextFile(convertFileSrc(filename)).then(
(ret) => { (ret) => {

View file

@ -161,7 +161,8 @@ li {
} }
.filetree-directory-button, .filetree-directory-button,
.filetree-file-button { .filetree-file-button,
.file-search-button {
background-color: transparent; background-color: transparent;
border: none; border: none;
width: 100%; width: 100%;
@ -201,7 +202,6 @@ li {
} }
dialog { dialog {
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
@ -213,7 +213,11 @@ dialog {
width: 50%; width: 50%;
height: 20%; height: 20%;
margin: auto; margin: auto;
/* display: flex; */
/* flex-direction: column; */
overflow: hidden;
} }
#file-search-dialog-input { #file-search-dialog-input {
border: solid; border: solid;
border-color: var(--accent-color); border-color: var(--accent-color);
@ -221,3 +225,9 @@ dialog {
border-top-left-radius: 10px; border-top-left-radius: 10px;
color: var(--text-color); color: var(--text-color);
} }
#file-search-results {
overflow: scroll;
grid-column: 1;
grid-row: 1;
}