Add focusing on obsidian elements

This commit is contained in:
Idrees Hassan
2025-11-13 18:41:37 -05:00
parent c312500f19
commit 71bb8204e2
10 changed files with 151 additions and 17 deletions

32
dist/birb.js vendored
View File

@@ -881,6 +881,17 @@
throw new Error("Method not implemented");
}
/**
* @returns {string[]} A list of CSS selectors for focusable elements
*/
getFocusableElements() {
return ["img", "video", ".birb-sticky-note"];
}
getFocusElementTopMargin() {
return 80;
}
/**
* @returns {string} The current path of the active page in this context
*/
@@ -1084,6 +1095,21 @@
this.putSaveData({});
}
/** @override */
getFocusElementTopMargin() {
return 10;
}
/** @override */
getFocusableElements() {
const elements = [
".workspace-leaf",
".cm-callout",
".HyperMD-codeblock-begin"
];
return super.getFocusableElements().concat(elements);
}
/** @override */
areStickyNotesEnabled() {
return false;
@@ -1795,7 +1821,6 @@
// Focus element constraints
const MIN_FOCUS_ELEMENT_WIDTH = 100;
const MIN_FOCUS_ELEMENT_TOP = 80;
/** @type {Partial<Settings>} */
let userSettings = {};
@@ -1924,7 +1949,7 @@
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.11.13.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.16"); }, false),
new MenuItem("2025.11.13.27", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.13.27"); }, false),
];
const styleElement = document.createElement("style");
@@ -2551,7 +2576,8 @@
if (frozen) {
return false;
}
const elements = document.querySelectorAll("img, video, .birb-sticky-note");
const MIN_FOCUS_ELEMENT_TOP = getContext().getFocusElementTopMargin();
const elements = document.querySelectorAll(getContext().getFocusableElements().join(", "));
const inWindow = Array.from(elements).filter((img) => {
const rect = img.getBoundingClientRect();
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();