mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Add focusing on obsidian elements
This commit is contained in:
@@ -104,7 +104,6 @@ const PET_FEATHER_BOOST = 2;
|
||||
|
||||
// Focus element constraints
|
||||
const MIN_FOCUS_ELEMENT_WIDTH = 100;
|
||||
const MIN_FOCUS_ELEMENT_TOP = 80;
|
||||
|
||||
/** @type {Partial<Settings>} */
|
||||
let userSettings = {};
|
||||
@@ -864,7 +863,8 @@ Promise.all([
|
||||
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();
|
||||
|
||||
@@ -42,6 +42,17 @@ export class Context {
|
||||
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
|
||||
*/
|
||||
@@ -245,6 +256,21 @@ class ObsidianContext extends Context {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user