Skip to content

Commit

Permalink
Revert "fix: Trail view in live preview doesn't scroll with the content"
Browse files Browse the repository at this point in the history
This reverts commit 52d2218.
  • Loading branch information
HEmile committed Jan 17, 2022
1 parent 3245a55 commit 045d04b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 192 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"license": "MIT",
"devDependencies": {
"@aidenlx/folder-note-core": "^1.3.1",
"@codemirror/language": "^0.19.0",
"@codemirror/rangeset": "^0.19.0",
"@codemirror/state": "^0.19.0",
"@codemirror/view": "^0.19.0",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
Expand All @@ -35,7 +31,7 @@
"auto-plugin-obsidian": "^0.1.4",
"eslint": "^7.29.0",
"mocha": "^9.1.3",
"obsidian": "^0.13.11",
"obsidian": "^0.12.0",
"obsidian-dataview": "^0.4.20",
"rollup": "^2.32.1",
"rollup-plugin-svelte": "7.1.0",
Expand Down
16 changes: 1 addition & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@ export default {
file: "main.js",
exports: "default",
},
external: ["obsidian", "fs", "os", "path",
"@codemirror/autocomplete",
"@codemirror/closebrackets",
"@codemirror/commands",
"@codemirror/fold",
"@codemirror/gutter",
"@codemirror/history",
"@codemirror/language",
"@codemirror/rangeset",
"@codemirror/rectangular-selection",
"@codemirror/search",
"@codemirror/state",
"@codemirror/stream-parser",
"@codemirror/text",
"@codemirror/view",],
external: ["obsidian", "fs", "os", "path"],
plugins: [
svelte({
emitCss: false,
Expand Down
15 changes: 1 addition & 14 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { DebugLevel, Relations, visTypes } from "./interfaces";
import type BCPlugin from "./main";
import MatrixView from "./Views/MatrixView";
import { getFields, splitAndTrim, strToRegex } from "./sharedFunctions";
import {drawTrail, updateLPView} from "./Views/TrailView";
import { drawTrail } from "./Views/TrailView";

const fragWithHTML = (html: string) =>
createFragment((frag) => (frag.createDiv().innerHTML = html));
Expand Down Expand Up @@ -485,7 +485,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showBCs = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand All @@ -501,7 +500,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showBCsInEditLPMode = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand Down Expand Up @@ -535,7 +533,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showTrail = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
});
})
.addToggle((toggle) => {
Expand All @@ -546,7 +543,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showGrid = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
});
})
.addToggle((toggle) => {
Expand All @@ -557,7 +553,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showJuggl = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
});
})
.addToggle((toggle) => {
Expand All @@ -568,7 +563,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.showPrevNext = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
});
});

Expand All @@ -582,7 +576,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.gridDots = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand Down Expand Up @@ -610,7 +603,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.gridHeatmap = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand Down Expand Up @@ -667,7 +659,6 @@ export class BCSettingTab extends PluginSettingTab {

await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand All @@ -682,7 +673,6 @@ export class BCSettingTab extends PluginSettingTab {

await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand All @@ -699,7 +689,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.trailSeperator = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand All @@ -716,7 +705,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.noPathMessage = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand All @@ -732,7 +720,6 @@ export class BCSettingTab extends PluginSettingTab {
settings.respectReadableLineLength = value;
await plugin.saveSettings();
await drawTrail(plugin);
updateLPView();
})
);

Expand Down
89 changes: 6 additions & 83 deletions src/Views/TrailView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MultiGraph } from "graphology";
import { error, info } from "loglevel";
import { MarkdownView, Notice, TFile, editorViewField } from "obsidian";
import { MarkdownView, Notice, TFile } from "obsidian";
import type { BCSettings } from "../interfaces";
import NextPrev from "../Components/NextPrev.svelte";
import TrailGrid from "../Components/TrailGrid.svelte";
Expand All @@ -16,70 +16,6 @@ import {
import type BCPlugin from "../main";
import { getFields, getRealnImplied } from "../sharedFunctions";
import {createJugglTrail} from "../Visualisations/Juggl";
import {Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate, WidgetType} from "@codemirror/view";
import {RangeSet, RangeSetBuilder} from "@codemirror/rangeset";

let UPDATE_LP_VIEW = false;

export function updateLPView() {
UPDATE_LP_VIEW = true;
}

export function buildCMPlugin(plugin: BCPlugin) {
class TrailWidget extends WidgetType {
element: HTMLElement;
constructor(element: HTMLElement) {
super();
this.element = element;
}

toDOM(view: EditorView): HTMLElement {
console.log("TO the doM!");
this.element.detach();
return this.element;
}

ignoreEvent(_event: Event): boolean {
return true;
}
}

return ViewPlugin.fromClass(
class {
decorations: DecorationSet;

constructor(view: EditorView) {
this.decorations = new RangeSetBuilder<Decoration>().finish();
this.buildDecorations(view).then(value => {this.decorations = value;});
}

update(update: ViewUpdate) {
if (UPDATE_LP_VIEW) {
this.buildDecorations(update.view).then(value => {this.decorations = value;});
UPDATE_LP_VIEW = false;
}
}

destroy() {}

async buildDecorations(view: EditorView) {
let builder = new RangeSetBuilder<Decoration>();
if (plugin.settings.showBCsInEditLPMode) {
let mdView: MarkdownView = view.state.field(editorViewField);
let element = await _drawTrail(plugin, mdView);
let widget = Decoration.widget({
widget: new TrailWidget(element)
});
builder.add(0, 0, widget);
}
return builder.finish();
}
},
{
decorations: v => v.decorations
}
)
}

function getLimitedTrailSub(plugin: BCPlugin) {
const { settings, mainG } = plugin;
Expand Down Expand Up @@ -134,15 +70,6 @@ function getBreadcrumbs(
}

export async function drawTrail(plugin: BCPlugin): Promise<void> {
const activeMDView = plugin.app.workspace.getActiveViewOfType(MarkdownView);
console.log(activeMDView.getMode());
if (activeMDView.getMode() !== "preview") {
return;
}
await _drawTrail(plugin, activeMDView);
}

async function _drawTrail(plugin: BCPlugin, activeMDView: MarkdownView): Promise<HTMLElement> {
try {
const { settings, db, app } = plugin;
const {
Expand All @@ -156,7 +83,7 @@ async function _drawTrail(plugin: BCPlugin, activeMDView: MarkdownView): Promise
showBCsInEditLPMode,
} = settings;
db.start2G("drawTrail");

const activeMDView = app.workspace.getActiveViewOfType(MarkdownView);
const mode = activeMDView?.getMode();
if (
!showBCs ||
Expand Down Expand Up @@ -189,16 +116,14 @@ async function _drawTrail(plugin: BCPlugin, activeMDView: MarkdownView): Promise
view = activeMDView.previewMode.containerEl.querySelector(
"div.markdown-preview-view"
);
activeMDView.containerEl
.querySelectorAll(".BC-trail")
?.forEach((trail) => trail.remove());
}
else {
} else {
view = activeMDView.contentEl.querySelector("div.markdown-source-view");
if (view.hasClass("is-live-preview")) livePreview = true;
}


activeMDView.containerEl
.querySelectorAll(".BC-trail")
?.forEach((trail) => trail.remove());

const closedUp = getLimitedTrailSub(plugin);
const sortedTrails = getBreadcrumbs(settings, closedUp, file);
Expand Down Expand Up @@ -269,7 +194,6 @@ async function _drawTrail(plugin: BCPlugin, activeMDView: MarkdownView): Promise
if (cmSizer) cmSizer.before(trailDiv);
}


trailDiv.empty();
if (settings.indexNotes.includes(basename)) {
trailDiv.innerText = "Index Note";
Expand Down Expand Up @@ -313,7 +237,6 @@ async function _drawTrail(plugin: BCPlugin, activeMDView: MarkdownView): Promise
);
}
db.end2G();
return trailDiv;
} catch (err) {
error(err);
plugin.db.end2G();
Expand Down
4 changes: 3 additions & 1 deletion src/Visualisations/Juggl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ export function createJugglTrail(
.split("\n")
.map((line) => {
const pair = line.split("- ");
return pair.slice(1).join("- ");
console.log({pair})
return pair[1];
})
.filter((pair) => pair && pair !== "");
let nodesS = new Set(lines);
nodesS.add(source);
const nodes = Array.from(nodesS).map(s => s + ".md");
console.log({nodes});

jugglDown = createJuggl(plugin, target, nodes, args);

Expand Down
7 changes: 2 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { getFields } from "./sharedFunctions";
import DucksView from "./Views/DucksView";
import MatrixView from "./Views/MatrixView";
import StatsView from "./Views/StatsView";
import {buildCMPlugin, drawTrail, UPDATE_LP_VIEW, updateLPView} from "./Views/TrailView";
import { drawTrail } from "./Views/TrailView";
import TreeView from "./Views/TreeView";
import { VisModal } from "./VisModal";

Expand Down Expand Up @@ -240,7 +240,7 @@ export default class BCPlugin extends Plugin {
callback: async () => {
settings.showBCsInEditLPMode = !settings.showBCsInEditLPMode;
await this.saveSettings();
updateLPView();
await drawTrail(this);
},
});

Expand Down Expand Up @@ -293,9 +293,6 @@ export default class BCPlugin extends Plugin {
() => new VisModal(this.app, this).open()
);

this.registerEditorExtension(buildCMPlugin(this));
console.log("Registered editor extension");

this.registerMarkdownCodeBlockProcessor(
"breadcrumbs",
getCodeblockCB(this)
Expand Down
Loading

0 comments on commit 045d04b

Please sign in to comment.