Skip to content

Commit

Permalink
fix measurement issue when sidebar is collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingislost committed Mar 2, 2022
1 parent dabddde commit 96ca759
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-query-control",
"name": "Query Control",
"version": "0.3.0",
"version": "0.3.1",
"minAppVersion": "0.12.5",
"description": "An experimental Obsidian plugin that adds additional control to queries",
"author": "NothingIsLost",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-query-control",
"name": "Query Control",
"version": "0.3.0",
"version": "0.3.1",
"minAppVersion": "0.12.5",
"description": "An experimental Obsidian plugin that adds additional control to queries",
"author": "NothingIsLost",
Expand Down
24 changes: 23 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ export default class EmbeddedQueryControlPlugin extends Plugin {
const plugin = this;
this.register(
around(searchView.constructor.prototype, {
onResize(old: any) {
return function (...args: any[]) {
// this works around measurement issues when the search el width
// goes to zero and then back to a non zero value
if (this.dom.el.clientWidth === 0) {
this.dom.children.forEach((child: any) => {
child.setCollapse(true, false);
});
this.dom.hidden = true;
}
else if (this.dom.hidden) {
this.dom.hidden = false;
// if we toggle too quickly, measurement happens before we want it to
setTimeout(() => {
this.dom.children.forEach((child: any) => {
child.setCollapse(this.dom.collapseAll, false);
});
}, 100);
}
return old.call(this, ...args);
};
},
stopSearch(old: any) {
return function (...args: any[]) {
const result = old.call(this, ...args);
Expand Down Expand Up @@ -358,7 +380,7 @@ export default class EmbeddedQueryControlPlugin extends Plugin {
onResultClick(old: any) {
return function (event: MouseEvent, e: any, ...args: any[]) {
if (
// TODO: Improve this exclusion list which allows for clicking
// TODO: Improve this exclusion list which allows for clicking
// on elements without navigating to the match result
event.target instanceof HTMLElement &&
(event.target.hasClass("internal-link") ||
Expand Down

0 comments on commit 96ca759

Please sign in to comment.