Skip to content

Commit

Permalink
0.0.8 Added line numbers to sidepane
Browse files Browse the repository at this point in the history
  • Loading branch information
TfT Hacker committed Sep 17, 2022
1 parent 7c4ee98 commit a723903
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian42-strange-new-worlds",
"name": "Obsidian42 - Strange New Worlds",
"version": "0.0.07",
"version": "0.0.08",
"minAppVersion": "0.16.2",
"description": "Revealing networked thought and the strange new worlds created by your vault",
"author": "TfTHacker",
Expand Down
2 changes: 1 addition & 1 deletion src/headerImageCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function processHeader(thePlugin: ThePlugin, mdView: MarkdownView) {
snwTitleRefCountDisplayCountEl.setAttribute("data-snw-type", "File");
snwTitleRefCountDisplayCountEl.setAttribute("data-snw-link", mdView.file.path);
snwTitleRefCountDisplayCountEl.ariaLabel = "Strange New Worlds\n" + fileList + "\n----\n-->Click for more details";
snwTitleRefCountDisplayCountEl.onclick = (e : MouseEvent) => processHtmlDecorationReferenceEvent(e, thePlugin);
snwTitleRefCountDisplayCountEl.onclick = (e : MouseEvent) => processHtmlDecorationReferenceEvent(e);

if(thePlugin.snwAPI.enableDebugging?.LinkCountInHeader)
thePlugin.snwAPI.console("snwTitleRefCountDisplayCountEl", snwTitleRefCountDisplayCountEl)
Expand Down
15 changes: 14 additions & 1 deletion src/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export interface Settings {
displayIncomingFilesheader: boolean;
displayInlineReferences: boolean;
displayEmbedReferencesInGutter: boolean;
displayLineNumberInSidebar: boolean;
}

export const DEFAULT_SETTINGS: Settings = {
displayIncomingFilesheader: true,
displayInlineReferences: true,
displayEmbedReferencesInGutter: true
displayEmbedReferencesInGutter: true,
displayLineNumberInSidebar: true
}

export class SettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -64,5 +66,16 @@ export class SettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName('Show line number for file in sidepane')
.setDesc(`Displays a line number from the document in the sidepane.` )
.addToggle((cb: ToggleComponent) => {
cb.setValue(this.plugin.settings.displayLineNumberInSidebar);
cb.onChange(async (value: boolean) => {
this.plugin.settings.displayLineNumberInSidebar = value;
await this.plugin.saveSettings();
});
});

}
}
23 changes: 6 additions & 17 deletions src/sidepane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ export class SidePaneView extends ItemView {
break;
case "File":
sidePaneResourceTypeTitle = "Target:";
sidePaneReferencesTitle = "Incoming links to target:";
sidePaneReferencesTitle = "Incoming links:";
Object.entries(getReferencesCache()).forEach((value, key)=>{ value[1].forEach((element:Link[]) => { if(element.resolvedFile.path === link) refCache.push(element)})});
break;
}


if(refCache.length===0) return; //This may get callled when Obsidian initializes. So if there are no references, just exit

//PANE HEADER
Expand All @@ -79,6 +78,7 @@ export class SidePaneView extends ItemView {

//REFERENCES TO THIS RESOURCE
const sourceLink = refType === "File" ? link : refCache[0]?.resolvedFile.path;
// sourceFileLineNumber will be 0 when doing a header lookup, but if its a reference will goto the right line
const sourceFileLineNumber = refType === "File" ? 0 : findPositionInFile(refCache[0].resolvedFile.path, refCache[0].reference.link.replace(refCache[0].resolvedFile.basename, "").replace("#^",""));
output += `<a class="internal-link snw-sidepane-link"
snw-data-line-number="${sourceFileLineNumber}"
Expand All @@ -96,14 +96,16 @@ export class SidePaneView extends ItemView {
//Loop through references and list them out
output += `<ul class="snw-sidepane-references">`;
sortedRefCache.forEach(ref => {
const refLineNumber = this.thePlugin.settings.displayLineNumberInSidebar ? `<span class="snw-sidepane-linenumber">(${ref.reference.position.start.line+1})</span>` : "";
output += `<li class="snw-sidepane-reference-item">`;
if(refType==="File") output += `<span class="snw-sidepane-reference-label-from">From: </span>`;
output += `<a class="internal-link snw-sidepane-link snw-sidepane-reference-item-from"
snw-data-line-number="${ref.reference.position.start.line}"
snw-data-file-name="${ref.sourceFile.path}"
data-href="${ref.sourceFile.path}"
href="${ref.sourceFile.path}">${ref.sourceFile.basename}</a><br/>`;
href="${ref.sourceFile.path}">${ref.sourceFile.basename}</a> ${refLineNumber}<br/>`;
if(refType==="File") {
console.log(ref)
const lineNumberResolvedFile = findPositionInFile(ref.resolvedFile.path, ref.reference.link.replace(ref.resolvedFile.basename,"").replace("#^",""));
output += `<span class="snw-sidepane-reference-label-to">To: </span>
<a class="internal-link snw-sidepane-link snw-sidepane-reference-item-to"
Expand Down Expand Up @@ -139,21 +141,8 @@ export class SidePaneView extends ItemView {
}
setTimeout(() => {
this.thePlugin.app.workspace.getActiveViewOfType(MarkdownView).setEphemeralState({line: LineNu });
}, 100);
}, 200);
});
// el.addEventListener('mouseover', (e: PointerEvent) => {
// const target = e.target as HTMLElement;
// const filePath = target.getAttribute("data-href");
// console.log(filePath)
// app.workspace.trigger("hover-link", {
// event: e,
// source: 'source',
// hoverParent: document.querySelector(".markdown-preview-view"),
// targetEl: null,
// linktext: filePath,
// });
// });

// @ts-ignore
if(this.app.internalPlugins.plugins['page-preview'].enabled===true) {
el.addEventListener('mouseover', (e: PointerEvent) => {
Expand Down
7 changes: 7 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
}

.snw-sidepane-container {
height: 100%;
}

.snw-header-count-wrapper {
Expand Down Expand Up @@ -86,6 +87,7 @@

.snw-sidepane-references {
margin-top: 0px;
padding-left: 20px;
}

.snw-sidepane-reference-item {
Expand All @@ -104,6 +106,11 @@
font-size: x-small;
}

.snw-sidepane-linenumber {
font-size: 7pt;
opacity: 0.7;
}

.snw-embed-special {
opacity: 1 !important;
font-size: 8pt;
Expand Down

0 comments on commit a723903

Please sign in to comment.