Skip to content

Commit

Permalink
Added Headline as breadcrumb above the body text.
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
boltex committed Apr 30, 2024
1 parent f242368 commit 7a72b37
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 3 deletions.
82 changes: 81 additions & 1 deletion leojs.leo
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<v t="felix.20240401213604.16"><vh>_fireSoon</vh></v>
</v>
</v>
<v t="felix.20240429203450.1"><vh>@clean src/leoBodyDocumentSymbolProvider.ts</vh></v>
<v t="felix.20201208223553.1"><vh>@clean src/leoOutline.ts</vh>
<v t="felix.20201209011931.1"><vh>class LeoOutlineProvider</vh>
<v t="felix.20201209011931.2"><vh>constructor</vh></v>
Expand Down Expand Up @@ -3652,6 +3653,7 @@ import { HelpPanel } from "./helpPanel";
import { UnlProvider } from "./unlProvider";
import { LeoBodyDetachedProvider } from "./leoBodyDetached";
import { Undoer } from "./core/leoUndo";
import { LeoBodyDocumentSymbolProvider } from "./leoBodyDocumentSymbolProvider";

@language typescript
@tabwidth -4
Expand Down Expand Up @@ -3922,6 +3924,7 @@ export class LeoUI extends NullGui {
private _changedDetachedWithMirrorBody = false;
private _bodyFileSystemStarted: boolean = false;
private _detachedFileSystemStarted: boolean = false;
private _leoBodyDocumentSymbolProvider!: LeoBodyDocumentSymbolProvider;
private _bodyEnablePreview: boolean = true;
private _leoFileSystem!: LeoBodyProvider; // as per https://code.visualstudio.com/api/extension-guides/virtual-documents#file-system-api
private _leoDetachedFileSystem!: LeoBodyDetachedProvider; // as per https://code.visualstudio.com/api/extension-guides/virtual-documents#file-system-api
Expand Down Expand Up @@ -8464,6 +8467,7 @@ import { BodyTimeInfo } from "./types";
import { LeoUI } from "./leoUI";
import * as g from './core/leoGlobals';
import { Constants } from "./constants";
import { VNode } from "./core/leoNodes";

@language typescript
@tabwidth -4
Expand Down Expand Up @@ -8507,6 +8511,7 @@ import { Constants } from "./constants";
const w_gnx = utils.leoUriToStr(p_uri);
if (this._openedBodiesInfo[w_gnx]) {
delete this._openedBodiesInfo[w_gnx];
delete this.openedBodiesVNodes[w_gnx];
} else {
// console.log("not deleted");
}
Expand Down Expand Up @@ -8557,6 +8562,7 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {
public watchedBodiesGnx: string[] = [];

// * List of gnx open in tab(s) (from tryApplyNodeToBody / switchBody and fs.delete)
public openedBodiesVNodes: { [key: string]: VNode } = {};
private _openedBodiesInfo: { [key: string]: BodyTimeInfo } = {};

private _lastBodyTimeGnx: string = "";
Expand Down Expand Up @@ -9705,6 +9711,20 @@ public finishStartup(): void {
this._leoFileSystem = new LeoBodyProvider(this);
this._leoDetachedFileSystem = new LeoBodyDetachedProvider(this);

// Register document symbol provider for 'breadcrumbs'
this._leoBodyDocumentSymbolProvider = new LeoBodyDocumentSymbolProvider(
this._leoFileSystem,
this._leoDetachedFileSystem
);
this._context.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider(
{ scheme: Constants.URI_LEOJS_SCHEME }, this._leoBodyDocumentSymbolProvider)
);
this._context.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider(
{ scheme: Constants.URI_LEOJS_DETACHED_SCHEME }, this._leoBodyDocumentSymbolProvider)
);

this._bodyMainSelectionColumn = 1;

// * Create Status bar Entry
Expand Down Expand Up @@ -12780,6 +12800,7 @@ private _tryApplyNodeToBody(

// first time or no body opened
this.bodyUri = utils.strToLeoUri(p_node.gnx);
this._leoFileSystem.openedBodiesVNodes[p_node.gnx] = p_node.v;
if (this._isBodyVisible() === 0 &amp;&amp; !this.showBodyIfClosed) {
return Promise.resolve();
}
Expand All @@ -12803,6 +12824,9 @@ private _switchBody(
const w_visibleCount = this._isBodyVisible();

this.bodyUri = w_newUri; // New GLOBAL BODY URI
if (this.lastSelectedNode) {
this._leoFileSystem.openedBodiesVNodes[this.lastSelectedNode.gnx] = this.lastSelectedNode.v;
}

if (w_visibleCount === 0 &amp;&amp; !this.showBodyIfClosed) {
return Promise.resolve();
Expand Down Expand Up @@ -18458,8 +18482,8 @@ public _onTabsChanged(p_event: vscode.TabChangeEvent): void {
for (const openBody of Object.keys(this._openedBodiesInfo)) {
if (!w_foundGnx.includes(openBody)) {
// Not an opened tab! remove it!

delete this._openedBodiesInfo[openBody];
delete this.openedBodiesVNodes[openBody];
}
}
}
Expand Down Expand Up @@ -18532,6 +18556,62 @@ private _refreshCommanderDetachedLanguage(): void {

- ...

</t>
<t tx="felix.20240429203450.1">import * as vscode from "vscode";
import { Constants } from "./constants";
import * as utils from "./utils";
import { LeoBodyProvider } from "./leoBody";
import { LeoBodyDetachedProvider } from "./leoBodyDetached";
import { VNode } from "./core/leoNodes";

export class LeoBodyDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
constructor(
private _leoBody: LeoBodyProvider,
private _leoDetached: LeoBodyDetachedProvider
) { }

public provideDocumentSymbols(
document: vscode.TextDocument, token: vscode.CancellationToken):
Thenable&lt;vscode.SymbolInformation[]&gt; {

const w_gnx = utils.leoUriToStr(document.uri);
let v: VNode | undefined;
let fileProvider;
if (
document.uri.scheme === Constants.URI_LEOJS_SCHEME
) {
fileProvider = this._leoBody;
} else {
fileProvider = this._leoDetached;
}
v = fileProvider.openedBodiesVNodes[w_gnx];
if (v) {

const c = v.context;

// const filename = c.shortFileName() || 'untitled';
const headline = v.headString();

// Get the last line number &amp; last character index of the last line
const lastLineIndex = document.lineCount - 1;
const lastCharIndex = document.lineAt(lastLineIndex).text.length;
const loc = new vscode.Location(document.uri, new vscode.Range(0, 0, lastLineIndex, lastCharIndex));

const breadcrumbInfo = new vscode.SymbolInformation(

// * BOTH
// filename + " &gt; " + headline, vscode.SymbolKind.String, "", loc

// * HEADLINE ONLY
headline, vscode.SymbolKind.String, "", loc

);
return Promise.resolve([breadcrumbInfo]);
}
return Promise.resolve([]);

}
}
</t>
<t tx="fil.20231216220210.1">## 0.2.5

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4487,4 +4487,4 @@
"showdown": "^2.1.0",
"stream": "^0.0.2"
}
}
}
5 changes: 4 additions & 1 deletion src/leoBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BodyTimeInfo } from "./types";
import { LeoUI } from "./leoUI";
import * as g from './core/leoGlobals';
import { Constants } from "./constants";
import { VNode } from "./core/leoNodes";

/**
* * Body panes implementation as a file system using "leojs" as a scheme identifier
Expand All @@ -24,6 +25,7 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {
public watchedBodiesGnx: string[] = [];

// * List of gnx open in tab(s) (from tryApplyNodeToBody / switchBody and fs.delete)
public openedBodiesVNodes: { [key: string]: VNode } = {};
private _openedBodiesInfo: { [key: string]: BodyTimeInfo } = {};

private _lastBodyTimeGnx: string = "";
Expand Down Expand Up @@ -89,8 +91,8 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {
for (const openBody of Object.keys(this._openedBodiesInfo)) {
if (!w_foundGnx.includes(openBody)) {
// Not an opened tab! remove it!

delete this._openedBodiesInfo[openBody];
delete this.openedBodiesVNodes[openBody];
}
}
}
Expand Down Expand Up @@ -237,6 +239,7 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {
const w_gnx = utils.leoUriToStr(p_uri);
if (this._openedBodiesInfo[w_gnx]) {
delete this._openedBodiesInfo[w_gnx];
delete this.openedBodiesVNodes[w_gnx];
} else {
// console.log("not deleted");
}
Expand Down
55 changes: 55 additions & 0 deletions src/leoBodyDocumentSymbolProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as vscode from "vscode";
import { Constants } from "./constants";
import * as utils from "./utils";
import { LeoBodyProvider } from "./leoBody";
import { LeoBodyDetachedProvider } from "./leoBodyDetached";
import { VNode } from "./core/leoNodes";

export class LeoBodyDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
constructor(
private _leoBody: LeoBodyProvider,
private _leoDetached: LeoBodyDetachedProvider
) { }

public provideDocumentSymbols(
document: vscode.TextDocument, token: vscode.CancellationToken):
Thenable<vscode.SymbolInformation[]> {

const w_gnx = utils.leoUriToStr(document.uri);
let v: VNode | undefined;
let fileProvider;
if (
document.uri.scheme === Constants.URI_LEOJS_SCHEME
) {
fileProvider = this._leoBody;
} else {
fileProvider = this._leoDetached;
}
v = fileProvider.openedBodiesVNodes[w_gnx];
if (v) {

const c = v.context;

// const filename = c.shortFileName() || 'untitled';
const headline = v.headString();

// Get the last line number & last character index of the last line
const lastLineIndex = document.lineCount - 1;
const lastCharIndex = document.lineAt(lastLineIndex).text.length;
const loc = new vscode.Location(document.uri, new vscode.Range(0, 0, lastLineIndex, lastCharIndex));

const breadcrumbInfo = new vscode.SymbolInformation(

// * BOTH
// filename + " > " + headline, vscode.SymbolKind.String, "", loc

// * HEADLINE ONLY
headline, vscode.SymbolKind.String, "", loc

);
return Promise.resolve([breadcrumbInfo]);
}
return Promise.resolve([]);

}
}
20 changes: 20 additions & 0 deletions src/leoUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { HelpPanel } from "./helpPanel";
import { UnlProvider } from "./unlProvider";
import { LeoBodyDetachedProvider } from "./leoBodyDetached";
import { Undoer } from "./core/leoUndo";
import { LeoBodyDocumentSymbolProvider } from "./leoBodyDocumentSymbolProvider";

/**
* Creates and manages instances of the UI elements along with their events
Expand Down Expand Up @@ -201,6 +202,7 @@ export class LeoUI extends NullGui {
private _changedDetachedWithMirrorBody = false;
private _bodyFileSystemStarted: boolean = false;
private _detachedFileSystemStarted: boolean = false;
private _leoBodyDocumentSymbolProvider!: LeoBodyDocumentSymbolProvider;
private _bodyEnablePreview: boolean = true;
private _leoFileSystem!: LeoBodyProvider; // as per https://code.visualstudio.com/api/extension-guides/virtual-documents#file-system-api
private _leoDetachedFileSystem!: LeoBodyDetachedProvider; // as per https://code.visualstudio.com/api/extension-guides/virtual-documents#file-system-api
Expand Down Expand Up @@ -485,6 +487,20 @@ export class LeoUI extends NullGui {
this._leoFileSystem = new LeoBodyProvider(this);
this._leoDetachedFileSystem = new LeoBodyDetachedProvider(this);

// Register document symbol provider for 'breadcrumbs'
this._leoBodyDocumentSymbolProvider = new LeoBodyDocumentSymbolProvider(
this._leoFileSystem,
this._leoDetachedFileSystem
);
this._context.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider(
{ scheme: Constants.URI_LEOJS_SCHEME }, this._leoBodyDocumentSymbolProvider)
);
this._context.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider(
{ scheme: Constants.URI_LEOJS_DETACHED_SCHEME }, this._leoBodyDocumentSymbolProvider)
);

this._bodyMainSelectionColumn = 1;

// * Create Status bar Entry
Expand Down Expand Up @@ -2591,6 +2607,7 @@ export class LeoUI extends NullGui {

// first time or no body opened
this.bodyUri = utils.strToLeoUri(p_node.gnx);
this._leoFileSystem.openedBodiesVNodes[p_node.gnx] = p_node.v;
if (this._isBodyVisible() === 0 && !this.showBodyIfClosed) {
return Promise.resolve();
}
Expand All @@ -2613,6 +2630,9 @@ export class LeoUI extends NullGui {
const w_visibleCount = this._isBodyVisible();

this.bodyUri = w_newUri; // New GLOBAL BODY URI
if (this.lastSelectedNode) {
this._leoFileSystem.openedBodiesVNodes[this.lastSelectedNode.gnx] = this.lastSelectedNode.v;
}

if (w_visibleCount === 0 && !this.showBodyIfClosed) {
return Promise.resolve();
Expand Down

0 comments on commit 7a72b37

Please sign in to comment.