mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-29 05:16:46 +02:00

* Bump versions * Bump NPM versions, update to Svelte 5 * try improve flaky test * bump single-file-cli, remove ublock origin workaround * bump base images * replace libssl3
45 lines
967 B
JavaScript
45 lines
967 B
JavaScript
export function debounce(callback, delay = 250) {
|
|
let timeoutId;
|
|
return (...args) => {
|
|
clearTimeout(timeoutId);
|
|
timeoutId = setTimeout(() => {
|
|
timeoutId = null;
|
|
callback(...args);
|
|
}, delay);
|
|
};
|
|
}
|
|
|
|
export function preventDefault(fn) {
|
|
return function (event) {
|
|
event.preventDefault();
|
|
fn.call(this, event);
|
|
};
|
|
}
|
|
|
|
export function clampText(text, maxChars = 30) {
|
|
if (!text || text.length <= 30) return text;
|
|
|
|
return text.substr(0, maxChars) + "...";
|
|
}
|
|
|
|
export function getCurrentWordBounds(input) {
|
|
const text = input.value;
|
|
const end = input.selectionStart;
|
|
let start = end;
|
|
|
|
let currentChar = text.charAt(start - 1);
|
|
|
|
while (currentChar && currentChar !== " " && start > 0) {
|
|
start--;
|
|
currentChar = text.charAt(start - 1);
|
|
}
|
|
|
|
return { start, end };
|
|
}
|
|
|
|
export function getCurrentWord(input) {
|
|
const bounds = getCurrentWordBounds(input);
|
|
|
|
return input.value.substring(bounds.start, bounds.end);
|
|
}
|