Delete frontend
This commit is contained in:
parent
c6261d9fc1
commit
cd308ad020
111 changed files with 0 additions and 15368 deletions
|
|
@ -1,55 +0,0 @@
|
||||||
import eslint from "@eslint/js";
|
|
||||||
import tseslint from "typescript-eslint";
|
|
||||||
import unusedImports from "eslint-plugin-unused-imports";
|
|
||||||
|
|
||||||
export default [
|
|
||||||
{
|
|
||||||
ignores: [
|
|
||||||
"sync-client/src/services/types.ts",
|
|
||||||
"**/dist/",
|
|
||||||
"**/*.mjs",
|
|
||||||
"**/*.js"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
...tseslint.config({
|
|
||||||
plugins: {
|
|
||||||
"unused-imports": unusedImports
|
|
||||||
},
|
|
||||||
extends: [eslint.configs.recommended, tseslint.configs.all],
|
|
||||||
rules: {
|
|
||||||
"no-unused-vars": "off",
|
|
||||||
"@typescript-eslint/restrict-template-expressions": "off",
|
|
||||||
"@typescript-eslint/no-unused-vars": "off",
|
|
||||||
"@typescript-eslint/no-floating-promises": "error",
|
|
||||||
"@typescript-eslint/parameter-properties": "off",
|
|
||||||
"@typescript-eslint/require-await": "off",
|
|
||||||
"@typescript-eslint/class-methods-use-this": "off",
|
|
||||||
"@typescript-eslint/consistent-return": "off",
|
|
||||||
"@typescript-eslint/no-unsafe-argument": "off",
|
|
||||||
"@typescript-eslint/max-params": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
max: 6
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@typescript-eslint/no-magic-numbers": "off",
|
|
||||||
"@typescript-eslint/prefer-readonly-parameter-types": "off",
|
|
||||||
"@typescript-eslint/naming-convention": "off",
|
|
||||||
"unused-imports/no-unused-vars": [
|
|
||||||
"warn",
|
|
||||||
{
|
|
||||||
vars: "all",
|
|
||||||
varsIgnorePattern: "^_",
|
|
||||||
args: "after-used",
|
|
||||||
argsIgnorePattern: "^_"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
projectService: true,
|
|
||||||
tsconfigRootDir: import.meta.dirname
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
# Obsidian Sample Plugin
|
|
||||||
|
|
||||||
This is a sample plugin for Obsidian (https://obsidian.md).
|
|
||||||
|
|
||||||
This project uses TypeScript to provide type checking and documentation.
|
|
||||||
The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definition format, which contains TSDoc comments describing what it does.
|
|
||||||
|
|
||||||
**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
|
|
||||||
|
|
||||||
This sample plugin demonstrates some of the basic functionality the plugin API can do.
|
|
||||||
- Adds a ribbon icon, which shows a Notice when clicked.
|
|
||||||
- Adds a command "Open Sample Modal" which opens a Modal.
|
|
||||||
- Adds a plugin setting tab to the settings page.
|
|
||||||
- Registers a global click event and output 'click' to the console.
|
|
||||||
- Registers a global interval which logs 'setInterval' to the console.
|
|
||||||
|
|
||||||
## First time developing plugins?
|
|
||||||
|
|
||||||
Quick starting guide for new plugin devs:
|
|
||||||
|
|
||||||
- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
|
|
||||||
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
|
|
||||||
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
|
|
||||||
- Install NodeJS, then run `npm i` in the command line under your repo folder.
|
|
||||||
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
|
|
||||||
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
|
|
||||||
- Reload Obsidian to load the new version of your plugin.
|
|
||||||
- Enable plugin in settings window.
|
|
||||||
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
|
|
||||||
|
|
||||||
## Releasing new releases
|
|
||||||
|
|
||||||
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
|
|
||||||
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
|
|
||||||
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
|
|
||||||
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
|
|
||||||
- Publish the release.
|
|
||||||
|
|
||||||
> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
|
|
||||||
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
|
|
||||||
|
|
||||||
## Adding your plugin to the community plugin list
|
|
||||||
|
|
||||||
- Check the [plugin guidelines](https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines).
|
|
||||||
- Publish an initial version.
|
|
||||||
- Make sure you have a `README.md` file in the root of your repo.
|
|
||||||
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
|
|
||||||
|
|
||||||
## How to use
|
|
||||||
|
|
||||||
- Clone this repo.
|
|
||||||
- Make sure your NodeJS is at least v16 (`node --version`).
|
|
||||||
- `npm i` or `yarn` to install dependencies.
|
|
||||||
- `npm run dev` to start compilation in watch mode.
|
|
||||||
|
|
||||||
## Manually installing the plugin
|
|
||||||
|
|
||||||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
|
|
||||||
|
|
||||||
|
|
||||||
## Funding URL
|
|
||||||
|
|
||||||
You can include funding URLs where people who use your plugin can financially support it.
|
|
||||||
|
|
||||||
The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"fundingUrl": "https://buymeacoffee.com"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you have multiple URLs, you can also do:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"fundingUrl": {
|
|
||||||
"Buy Me a Coffee": "https://buymeacoffee.com",
|
|
||||||
"GitHub Sponsor": "https://github.com/sponsors",
|
|
||||||
"Patreon": "https://www.patreon.com/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## API Documentation
|
|
||||||
|
|
||||||
See https://github.com/obsidianmd/obsidian-api
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
preset: "ts-jest/presets/js-with-babel-esm"
|
|
||||||
};
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"id": "vault-link",
|
|
||||||
"name": "VaultLink",
|
|
||||||
"version": "0.4.0",
|
|
||||||
"minAppVersion": "0.0.0",
|
|
||||||
"description": "Self-hosted synchronization and collaboration for your Vault.",
|
|
||||||
"author": "Andras Schmelczer",
|
|
||||||
"authorUrl": "https://schmelczer.dev",
|
|
||||||
"isDesktopOnly": false
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
{
|
|
||||||
"name": "vault-link-obsidian-plugin",
|
|
||||||
"version": "0.4.0",
|
|
||||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
|
||||||
"main": "main.js",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "webpack watch --mode development",
|
|
||||||
"build": "webpack --mode production",
|
|
||||||
"test": "jest",
|
|
||||||
"version": "node version-bump.mjs"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "MIT",
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/jest": "^29.5.14",
|
|
||||||
"@types/node": "^22.15.30",
|
|
||||||
"css-loader": "^7.1.2",
|
|
||||||
"date-fns": "^4.1.0",
|
|
||||||
"file-loader": "^6.2.0",
|
|
||||||
"fs-extra": "^11.3.0",
|
|
||||||
"jest": "^29.7.0",
|
|
||||||
"mini-css-extract-plugin": "^2.9.2",
|
|
||||||
"obsidian": "1.8.7",
|
|
||||||
"resolve-url-loader": "^5.0.0",
|
|
||||||
"sass": "^1.89.1",
|
|
||||||
"sass-loader": "^16.0.5",
|
|
||||||
"sync-client": "file:../sync-client",
|
|
||||||
"terser-webpack-plugin": "^5.3.14",
|
|
||||||
"ts-jest": "^29.3.4",
|
|
||||||
"ts-loader": "^9.5.2",
|
|
||||||
"tslib": "2.8.1",
|
|
||||||
"typescript": "5.8.3",
|
|
||||||
"url": "^0.11.4",
|
|
||||||
"virtual-scroller": "^1.13.1",
|
|
||||||
"webpack": "^5.99.9",
|
|
||||||
"webpack-cli": "^6.0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,178 +0,0 @@
|
||||||
import type { Stat, Vault, Workspace } from "obsidian";
|
|
||||||
import { MarkdownView, normalizePath } from "obsidian";
|
|
||||||
import type {
|
|
||||||
FileSystemOperations,
|
|
||||||
RelativePath,
|
|
||||||
TextWithCursors
|
|
||||||
} from "sync-client";
|
|
||||||
import { lineAndColumnToPosition } from "./utils/line-and-column-to-position";
|
|
||||||
import { positionToLineAndColumn } from "./utils/position-to-line-and-column";
|
|
||||||
import { getCursorsFromEditor } from "./views/cursors/get-cursors-from-editor";
|
|
||||||
|
|
||||||
export class ObsidianFileSystemOperations implements FileSystemOperations {
|
|
||||||
public constructor(
|
|
||||||
private readonly vault: Vault,
|
|
||||||
private readonly workspace: Workspace
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public async listAllFiles(): Promise<RelativePath[]> {
|
|
||||||
// Let's implement this by hand because vault.adapter.listAllFiles doesn't always return all files.
|
|
||||||
const allFiles = [];
|
|
||||||
const remainingFolders = [this.vault.getRoot().path];
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
||||||
while (true) {
|
|
||||||
const folder = remainingFolders.pop();
|
|
||||||
if (folder == undefined) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This would be a very bad idea to sync as it would mess with
|
|
||||||
// the integrity of the sync database.
|
|
||||||
if (folder.endsWith(".obsidian/plugins/vault-link/data.json")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = await this.vault.adapter.list(normalizePath(folder));
|
|
||||||
allFiles.push(...files.files);
|
|
||||||
remainingFolders.push(...files.folders);
|
|
||||||
}
|
|
||||||
|
|
||||||
return allFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async read(path: RelativePath): Promise<Uint8Array> {
|
|
||||||
path = normalizePath(path);
|
|
||||||
const view = this.workspace.getActiveViewOfType(MarkdownView);
|
|
||||||
if (view?.file?.path === path) {
|
|
||||||
return new TextEncoder().encode(view.editor.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Uint8Array(await this.vault.adapter.readBinary(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async write(path: RelativePath, content: Uint8Array): Promise<void> {
|
|
||||||
path = normalizePath(path);
|
|
||||||
|
|
||||||
const view = this.workspace.getActiveViewOfType(MarkdownView);
|
|
||||||
if (view?.file?.path === path) {
|
|
||||||
const position = view.editor.getCursor();
|
|
||||||
view.editor.setValue(new TextDecoder().decode(content));
|
|
||||||
view.editor.setCursor(position);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.vault.adapter.writeBinary(
|
|
||||||
path,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
||||||
content.buffer as ArrayBuffer
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async atomicUpdateText(
|
|
||||||
path: RelativePath,
|
|
||||||
updater: (current: TextWithCursors) => TextWithCursors
|
|
||||||
): Promise<string> {
|
|
||||||
path = normalizePath(path);
|
|
||||||
|
|
||||||
const view = this.workspace.getActiveViewOfType(MarkdownView);
|
|
||||||
|
|
||||||
if (view?.file?.path === path) {
|
|
||||||
const text = view.editor.getValue();
|
|
||||||
|
|
||||||
const cursors = getCursorsFromEditor(view.editor).flatMap(
|
|
||||||
({ id, start: anchor, end: head }) => [
|
|
||||||
{
|
|
||||||
id: 2 * id,
|
|
||||||
characterPosition: anchor
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2 * id + 1,
|
|
||||||
characterPosition: head
|
|
||||||
}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = updater({
|
|
||||||
text,
|
|
||||||
cursors
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.text === text) {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
view.editor.setValue(result.text);
|
|
||||||
|
|
||||||
const selections = [];
|
|
||||||
for (let i = 0; i < result.cursors.length / 2; i++) {
|
|
||||||
const from = result.cursors[2 * i];
|
|
||||||
const to = result.cursors[2 * i + 1];
|
|
||||||
const { line: fromLine, column: fromColumn } =
|
|
||||||
positionToLineAndColumn(
|
|
||||||
result.text,
|
|
||||||
from.characterPosition
|
|
||||||
);
|
|
||||||
|
|
||||||
const { line: toLine, column: toColumn } =
|
|
||||||
positionToLineAndColumn(result.text, to.characterPosition);
|
|
||||||
|
|
||||||
selections.push({
|
|
||||||
anchor: { line: fromLine, ch: fromColumn },
|
|
||||||
head: { line: toLine, ch: toColumn }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
view.editor.setSelections(selections);
|
|
||||||
|
|
||||||
return result.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.vault.adapter.process(
|
|
||||||
path,
|
|
||||||
(text) =>
|
|
||||||
updater({
|
|
||||||
text,
|
|
||||||
cursors: []
|
|
||||||
}).text
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getFileSize(path: RelativePath): Promise<number> {
|
|
||||||
return (await this.statFile(path)).size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getModificationTime(path: RelativePath): Promise<Date> {
|
|
||||||
return new Date((await this.statFile(path)).mtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async exists(path: RelativePath): Promise<boolean> {
|
|
||||||
return this.vault.adapter.exists(normalizePath(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createDirectory(path: RelativePath): Promise<void> {
|
|
||||||
return this.vault.adapter.mkdir(normalizePath(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async delete(path: RelativePath): Promise<void> {
|
|
||||||
if (!(await this.vault.adapter.trashSystem(normalizePath(path)))) {
|
|
||||||
return this.vault.adapter.remove(normalizePath(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async rename(
|
|
||||||
oldPath: RelativePath,
|
|
||||||
newPath: RelativePath
|
|
||||||
): Promise<void> {
|
|
||||||
return this.vault.adapter.rename(oldPath, newPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async statFile(path: string): Promise<Stat> {
|
|
||||||
const file = await this.vault.adapter.stat(normalizePath(path));
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
throw new Error(`File not found: ${path}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
export function getRandomColor(name: string): string {
|
|
||||||
let hash = 0;
|
|
||||||
for (let i = 0; i < name.length; i++) {
|
|
||||||
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
||||||
hash |= 0; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
const normalised = hash / 0x7fffffff;
|
|
||||||
return `hsl(${Math.abs(normalised * 360)}, 55%, 55%)`; // HSL color
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
import { lineAndColumnToPosition } from "./line-and-column-to-position";
|
|
||||||
|
|
||||||
describe("lineAndColumnToPosition", () => {
|
|
||||||
it("should return the correct position for the first line", () => {
|
|
||||||
const text = "Hello\nWorld";
|
|
||||||
const position = lineAndColumnToPosition(text, 0, 3);
|
|
||||||
expect(position).toBe(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return the correct position for the second line", () => {
|
|
||||||
const text = "Hello\nWorld";
|
|
||||||
const position = lineAndColumnToPosition(text, 1, 2);
|
|
||||||
expect(position).toBe(8);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return the correct position for an empty string", () => {
|
|
||||||
const text = "";
|
|
||||||
const position = lineAndColumnToPosition(text, 0, 0);
|
|
||||||
expect(position).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("with carrige return", () => {
|
|
||||||
expect(lineAndColumnToPosition("a\nb", 1, 1)).toBe(3);
|
|
||||||
expect(lineAndColumnToPosition("a\r\nb", 1, 1)).toBe(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle multi-line strings with varying lengths", () => {
|
|
||||||
const text = "Line1\nLongerLine2\nShort3";
|
|
||||||
const position = lineAndColumnToPosition(text, 2, 4);
|
|
||||||
expect(position).toBe(22);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw an error if the line number is out of range", () => {
|
|
||||||
const text = "Line1\nLine2";
|
|
||||||
expect(() => lineAndColumnToPosition(text, 3, 0)).toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw an error if the column number is out of range", () => {
|
|
||||||
const text = "Line1\nLine2";
|
|
||||||
expect(() => lineAndColumnToPosition(text, 1, 10)).toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/**
|
|
||||||
* Converts line and column coordinates to an absolute character position in a text string.
|
|
||||||
*
|
|
||||||
* @param line - The zero-based line number
|
|
||||||
* @param column - The zero-based column number
|
|
||||||
* @param text - The text string to calculate position in
|
|
||||||
* @returns The absolute character position (zero-based index) in the text string
|
|
||||||
* @throws Error if line number is out of range
|
|
||||||
* @throws Error if column number is out of range
|
|
||||||
*/
|
|
||||||
export function lineAndColumnToPosition(
|
|
||||||
text: string,
|
|
||||||
line: number,
|
|
||||||
column: number
|
|
||||||
): number {
|
|
||||||
const lines = text.replace("\r", "").split("\n");
|
|
||||||
|
|
||||||
if (line >= lines.length) {
|
|
||||||
throw new Error(`Line number ${line} is out of range.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column > lines[line].length) {
|
|
||||||
throw new Error(`Column number ${column} is out of range.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let position = 0;
|
|
||||||
for (let i = 0; i < line; i++) {
|
|
||||||
position += lines[i].length + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
position += column;
|
|
||||||
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
import { positionToLineAndColumn } from "./position-to-line-and-column";
|
|
||||||
|
|
||||||
describe("positionToLineAndColumn", () => {
|
|
||||||
test("converts position to line and column in multi-line text", () => {
|
|
||||||
const text = "ab\ncd\n";
|
|
||||||
expect(positionToLineAndColumn(text, 0)).toEqual({
|
|
||||||
line: 0,
|
|
||||||
column: 0
|
|
||||||
});
|
|
||||||
expect(positionToLineAndColumn(text, 1)).toEqual({
|
|
||||||
line: 0,
|
|
||||||
column: 1
|
|
||||||
});
|
|
||||||
expect(positionToLineAndColumn(text, 2)).toEqual({
|
|
||||||
line: 0,
|
|
||||||
column: 2
|
|
||||||
});
|
|
||||||
expect(positionToLineAndColumn(text, 3)).toEqual({
|
|
||||||
line: 1,
|
|
||||||
column: 0
|
|
||||||
});
|
|
||||||
expect(positionToLineAndColumn(text, 4)).toEqual({
|
|
||||||
line: 1,
|
|
||||||
column: 1
|
|
||||||
});
|
|
||||||
expect(positionToLineAndColumn(text, 6)).toEqual({
|
|
||||||
line: 2,
|
|
||||||
column: 0
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with carrige returns", () => {
|
|
||||||
expect(positionToLineAndColumn("a\nb", 3)).toEqual({
|
|
||||||
line: 1,
|
|
||||||
column: 1
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(positionToLineAndColumn("a\r\nb", 3)).toEqual({
|
|
||||||
line: 1,
|
|
||||||
column: 1
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles empty input", () => {
|
|
||||||
expect(positionToLineAndColumn("", 0)).toEqual({ line: 0, column: 0 });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles positions at the end of text", () => {
|
|
||||||
const text = "End";
|
|
||||||
expect(positionToLineAndColumn(text, 3)).toEqual({
|
|
||||||
line: 0,
|
|
||||||
column: 3
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("throws error for position out of range", () => {
|
|
||||||
const text = "Short text";
|
|
||||||
expect(() => positionToLineAndColumn(text, 15)).toThrow();
|
|
||||||
expect(() => positionToLineAndColumn(text, -1)).toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/**
|
|
||||||
* Converts a character position in text to line and column numbers.
|
|
||||||
*
|
|
||||||
* @param text The text content to analyze
|
|
||||||
* @param position The character position to convert
|
|
||||||
* @returns An object containing line and column numbers
|
|
||||||
* @throws Will throw an error if the position is negative or exceeds the text length
|
|
||||||
*/
|
|
||||||
export function positionToLineAndColumn(
|
|
||||||
text: string,
|
|
||||||
position: number
|
|
||||||
): { line: number; column: number } {
|
|
||||||
if (position < 0) {
|
|
||||||
throw new Error("Position cannot be negative");
|
|
||||||
}
|
|
||||||
|
|
||||||
text = text.replace("\r", "");
|
|
||||||
|
|
||||||
if (
|
|
||||||
position >
|
|
||||||
text.length + 1
|
|
||||||
// +1 to account for the cursor being after last character
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
`Position ${position} exceeds text length ${text.length}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const textUpToPosition = text.substring(0, position);
|
|
||||||
const lines = textUpToPosition.split("\n");
|
|
||||||
|
|
||||||
const line = lines.length - 1;
|
|
||||||
const column = lines[lines.length - 1].length;
|
|
||||||
|
|
||||||
return { line, column };
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
import type { LogLine, SyncClient } from "sync-client";
|
|
||||||
import { LogLevel } from "sync-client";
|
|
||||||
|
|
||||||
export function registerConsoleForLogging(client: SyncClient): void {
|
|
||||||
client.logger.addOnMessageListener((logLine: LogLine) => {
|
|
||||||
const formatted = `${logLine.timestamp.toISOString()} ${logLine.level} ${logLine.message}`;
|
|
||||||
|
|
||||||
switch (logLine.level) {
|
|
||||||
case LogLevel.ERROR:
|
|
||||||
console.error(formatted);
|
|
||||||
break;
|
|
||||||
case LogLevel.WARNING:
|
|
||||||
console.warn(formatted);
|
|
||||||
break;
|
|
||||||
case LogLevel.INFO:
|
|
||||||
console.info(formatted);
|
|
||||||
break;
|
|
||||||
case LogLevel.DEBUG:
|
|
||||||
console.debug(formatted);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,220 +0,0 @@
|
||||||
import type {
|
|
||||||
Editor,
|
|
||||||
EventRef,
|
|
||||||
MarkdownFileInfo,
|
|
||||||
TAbstractFile,
|
|
||||||
Workspace,
|
|
||||||
WorkspaceLeaf
|
|
||||||
} from "obsidian";
|
|
||||||
import type { MarkdownView } from "obsidian";
|
|
||||||
import { Platform, Plugin, TFile } from "obsidian";
|
|
||||||
import "../manifest.json";
|
|
||||||
import { HistoryView } from "./views/history/history-view";
|
|
||||||
import { StatusBar } from "./views/status-bar/status-bar";
|
|
||||||
import { LogsView } from "./views/logs/logs-view";
|
|
||||||
import { StatusDescription } from "./views/status-description/status-description";
|
|
||||||
import type { CursorSpan, RelativePath } from "sync-client";
|
|
||||||
import { SyncClient, rateLimit, DEFAULT_SETTINGS } from "sync-client";
|
|
||||||
import { ObsidianFileSystemOperations } from "./obsidian-file-system";
|
|
||||||
import { SyncSettingsTab } from "./views/settings/settings-tab";
|
|
||||||
import { registerConsoleForLogging } from "./utils/register-console-for-logging";
|
|
||||||
import { updateEditorStatusDisplay } from "./views/editor-sync-line/editor-sync-line";
|
|
||||||
import { remoteCursorsTheme } from "./views/cursors/remote-cursor-theme";
|
|
||||||
import {
|
|
||||||
remoteCursorsPlugin,
|
|
||||||
setCursors
|
|
||||||
} from "./views/cursors/remote-cursors-plugin";
|
|
||||||
import { getCursorsFromEditor } from "./views/cursors/get-cursors-from-editor";
|
|
||||||
import { LocalCursorUpdateListener } from "./views/cursors/local-cursor-update-listener";
|
|
||||||
|
|
||||||
const MIN_WAIT_BETWEEN_UPDATES_IN_MS = 250;
|
|
||||||
export default class VaultLinkPlugin extends Plugin {
|
|
||||||
private readonly disposables: (() => unknown)[] = [];
|
|
||||||
|
|
||||||
private settingsTab: SyncSettingsTab | undefined;
|
|
||||||
private client!: SyncClient;
|
|
||||||
private readonly rateLimitedUpdatesPerFile = new Map<
|
|
||||||
string,
|
|
||||||
() => Promise<unknown>
|
|
||||||
>();
|
|
||||||
|
|
||||||
public async onload(): Promise<void> {
|
|
||||||
DEFAULT_SETTINGS.ignorePatterns.push(
|
|
||||||
".obsidian/**",
|
|
||||||
".git/**",
|
|
||||||
".trash/**"
|
|
||||||
);
|
|
||||||
|
|
||||||
this.client = await SyncClient.create({
|
|
||||||
fs: new ObsidianFileSystemOperations(
|
|
||||||
this.app.vault,
|
|
||||||
this.app.workspace
|
|
||||||
),
|
|
||||||
persistence: {
|
|
||||||
load: this.loadData.bind(this),
|
|
||||||
save: this.saveData.bind(this)
|
|
||||||
},
|
|
||||||
nativeLineEndings: Platform.isWin ? "\r\n" : "\n"
|
|
||||||
});
|
|
||||||
|
|
||||||
registerConsoleForLogging(this.client);
|
|
||||||
|
|
||||||
const statusDescription = new StatusDescription(this.client);
|
|
||||||
|
|
||||||
this.settingsTab = new SyncSettingsTab({
|
|
||||||
app: this.app,
|
|
||||||
plugin: this,
|
|
||||||
syncClient: this.client,
|
|
||||||
statusDescription
|
|
||||||
});
|
|
||||||
this.addSettingTab(this.settingsTab);
|
|
||||||
|
|
||||||
new StatusBar(this, this.client);
|
|
||||||
|
|
||||||
this.registerView(
|
|
||||||
HistoryView.TYPE,
|
|
||||||
(leaf) => new HistoryView(this.client, leaf)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.registerView(
|
|
||||||
LogsView.TYPE,
|
|
||||||
(leaf) => new LogsView(this.client, leaf)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.registerEditorExtension([remoteCursorsTheme, remoteCursorsPlugin]);
|
|
||||||
|
|
||||||
this.client.addRemoteCursorsUpdateListener((cursors) => {
|
|
||||||
setCursors(cursors, this.app);
|
|
||||||
});
|
|
||||||
|
|
||||||
const cursorListener = new LocalCursorUpdateListener(
|
|
||||||
this.client,
|
|
||||||
this.app.workspace
|
|
||||||
);
|
|
||||||
this.disposables.push(() => {
|
|
||||||
cursorListener.dispose();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.app.workspace.updateOptions();
|
|
||||||
|
|
||||||
this.addRibbonIcon(
|
|
||||||
HistoryView.ICON,
|
|
||||||
"Open VaultLink events",
|
|
||||||
async (_: MouseEvent) => this.activateView(HistoryView.TYPE)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.addRibbonIcon(
|
|
||||||
LogsView.ICON,
|
|
||||||
"Open VaultLink logs",
|
|
||||||
async (_: MouseEvent) => this.activateView(LogsView.TYPE)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.app.workspace.onLayoutReady(async () => {
|
|
||||||
this.registerEditorEvents();
|
|
||||||
void this.client.start();
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
updateEditorStatusDisplay(this.app.workspace, this.client);
|
|
||||||
}, 200);
|
|
||||||
this.disposables.push(() => {
|
|
||||||
clearInterval(interval);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public onunload(): void {
|
|
||||||
this.client.stop();
|
|
||||||
this.disposables.forEach((disposable) => {
|
|
||||||
disposable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public openSettings(): void {
|
|
||||||
// eslint-disable-next-line
|
|
||||||
(this.app as any).setting.open(); // this is undocumented
|
|
||||||
// eslint-disable-next-line
|
|
||||||
(this.app as any).setting.openTab(this.settingsTab); // this is undocumented
|
|
||||||
}
|
|
||||||
|
|
||||||
public closeSettings(): void {
|
|
||||||
// eslint-disable-next-line
|
|
||||||
(this.app as any).setting.close(); // this is undocumented
|
|
||||||
}
|
|
||||||
|
|
||||||
public async activateView(type: string): Promise<void> {
|
|
||||||
const { workspace } = this.app;
|
|
||||||
|
|
||||||
let leaf: WorkspaceLeaf | null = null;
|
|
||||||
const leaves = workspace.getLeavesOfType(type);
|
|
||||||
|
|
||||||
if (leaves.length > 0) {
|
|
||||||
[leaf] = leaves;
|
|
||||||
} else {
|
|
||||||
leaf = workspace.getRightLeaf(false);
|
|
||||||
await leaf?.setViewState({ type: type, active: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leaf) {
|
|
||||||
await workspace.revealLeaf(leaf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private registerEditorEvents(): void {
|
|
||||||
[
|
|
||||||
this.app.workspace.on(
|
|
||||||
"editor-change",
|
|
||||||
async (
|
|
||||||
_editor: Editor,
|
|
||||||
info: MarkdownView | MarkdownFileInfo
|
|
||||||
) => {
|
|
||||||
const { file } = info;
|
|
||||||
if (file) {
|
|
||||||
await this.rateLimitedUpdate(file.path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.app.vault.on("create", async (file: TAbstractFile) => {
|
|
||||||
if (file instanceof TFile) {
|
|
||||||
await this.client.syncLocallyCreatedFile(file.path);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
this.app.vault.on("modify", async (file: TAbstractFile) => {
|
|
||||||
if (file instanceof TFile) {
|
|
||||||
await this.rateLimitedUpdate(file.path);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
this.app.vault.on("delete", async (file: TAbstractFile) => {
|
|
||||||
await this.client.syncLocallyDeletedFile(file.path);
|
|
||||||
}),
|
|
||||||
this.app.vault.on(
|
|
||||||
"rename",
|
|
||||||
async (file: TAbstractFile, oldPath: string) => {
|
|
||||||
if (file instanceof TFile) {
|
|
||||||
await this.client.syncLocallyUpdatedFile({
|
|
||||||
oldPath,
|
|
||||||
relativePath: file.path
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
].forEach((event) => {
|
|
||||||
this.registerEvent(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async rateLimitedUpdate(path: string): Promise<void> {
|
|
||||||
if (!this.rateLimitedUpdatesPerFile.has(path)) {
|
|
||||||
this.rateLimitedUpdatesPerFile.set(
|
|
||||||
path,
|
|
||||||
rateLimit(
|
|
||||||
async () =>
|
|
||||||
this.client.syncLocallyUpdatedFile({
|
|
||||||
relativePath: path
|
|
||||||
}),
|
|
||||||
MIN_WAIT_BETWEEN_UPDATES_IN_MS
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await this.rateLimitedUpdatesPerFile.get(path)?.();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import type { Editor } from "obsidian";
|
|
||||||
import { lineAndColumnToPosition } from "../../utils/line-and-column-to-position";
|
|
||||||
|
|
||||||
export interface Cursor {
|
|
||||||
id: number;
|
|
||||||
start: number;
|
|
||||||
end: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCursorsFromEditor(editor: Editor): Cursor[] {
|
|
||||||
const text = editor.getValue();
|
|
||||||
return editor.listSelections().map(({ anchor, head }, i) => ({
|
|
||||||
id: i,
|
|
||||||
start: lineAndColumnToPosition(text, anchor.line, anchor.ch),
|
|
||||||
end: lineAndColumnToPosition(text, head.line, head.ch)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
import type { Workspace } from "obsidian";
|
|
||||||
import { EventRef, Editor, MarkdownView, MarkdownFileInfo } from "obsidian";
|
|
||||||
import type { Logger, SyncClient } from "sync-client";
|
|
||||||
import type { Cursor } from "./get-cursors-from-editor";
|
|
||||||
import { getCursorsFromEditor } from "./get-cursors-from-editor";
|
|
||||||
|
|
||||||
export class LocalCursorUpdateListener {
|
|
||||||
private static readonly UPDATE_INTERVAL_MS = 50;
|
|
||||||
private readonly eventHandle: NodeJS.Timeout;
|
|
||||||
private lastCursorState: Record<string, Cursor[]> = {};
|
|
||||||
|
|
||||||
public constructor(
|
|
||||||
private readonly client: SyncClient,
|
|
||||||
private readonly workspace: Workspace
|
|
||||||
) {
|
|
||||||
this.eventHandle = setInterval(() => {
|
|
||||||
this.updateAllCursors();
|
|
||||||
}, LocalCursorUpdateListener.UPDATE_INTERVAL_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public dispose(): void {
|
|
||||||
clearInterval(this.eventHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateAllCursors(): void {
|
|
||||||
const currentCursors = this.getAllCursors();
|
|
||||||
if (
|
|
||||||
JSON.stringify(this.lastCursorState) ===
|
|
||||||
JSON.stringify(currentCursors)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastCursorState = currentCursors;
|
|
||||||
this.client
|
|
||||||
.updateLocalCursors(currentCursors)
|
|
||||||
.catch((error: unknown) => {
|
|
||||||
this.client.logger.error(
|
|
||||||
`Failed to update local cursors: ${error}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAllCursors(): Record<string, Cursor[]> {
|
|
||||||
const cursors: Record<string, Cursor[]> = {};
|
|
||||||
this.workspace
|
|
||||||
.getLeavesOfType("markdown")
|
|
||||||
.map((leaf) => leaf.view)
|
|
||||||
.filter((view) => view instanceof MarkdownView)
|
|
||||||
.forEach((view) => {
|
|
||||||
const { file } = view;
|
|
||||||
if (!file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cursors[file.path] = getCursorsFromEditor(view.editor);
|
|
||||||
});
|
|
||||||
return cursors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
import { EditorView } from "@codemirror/view";
|
|
||||||
|
|
||||||
const CARET_WIDTH = 2;
|
|
||||||
const DOT_RADIUS = 4;
|
|
||||||
|
|
||||||
export const remoteCursorsTheme = EditorView.baseTheme({
|
|
||||||
".selection-caret": {
|
|
||||||
position: "relative"
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret > *": {
|
|
||||||
position: "absolute",
|
|
||||||
backgroundColor: "inherit"
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret > .stick": {
|
|
||||||
left: 0,
|
|
||||||
top: 0,
|
|
||||||
transform: "translateX(-50%)",
|
|
||||||
width: `${CARET_WIDTH}px`,
|
|
||||||
height: "100%",
|
|
||||||
display: "block",
|
|
||||||
borderRadius: `${CARET_WIDTH / 2}px`,
|
|
||||||
animation: "blink-stick 1s steps(1) infinite"
|
|
||||||
},
|
|
||||||
|
|
||||||
"@keyframes blink-stick": {
|
|
||||||
"0%, 100%": { opacity: 1 },
|
|
||||||
"50%": { opacity: 0 }
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret > .dot": {
|
|
||||||
borderRadius: "50%",
|
|
||||||
width: `${DOT_RADIUS * 2}px`,
|
|
||||||
height: `${DOT_RADIUS * 2}px`,
|
|
||||||
top: `-${DOT_RADIUS}px`,
|
|
||||||
left: `-${DOT_RADIUS}px`,
|
|
||||||
transition: "transform .3s ease-in-out",
|
|
||||||
transformOrigin: "bottom center",
|
|
||||||
boxSizing: "border-box"
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret:hover > .dot": {
|
|
||||||
transform: "scale(0)"
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret > .info": {
|
|
||||||
top: "-1.3em",
|
|
||||||
left: `-${CARET_WIDTH / 2}px`,
|
|
||||||
fontSize: "0.9em",
|
|
||||||
userSelect: "none",
|
|
||||||
color: "white",
|
|
||||||
padding: "0 2px",
|
|
||||||
transition: "opacity .3s ease-in-out",
|
|
||||||
opacity: 0,
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
borderRadius: "3px 3px 3px 0"
|
|
||||||
},
|
|
||||||
|
|
||||||
".selection-caret:hover > .info": {
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
import { AnnotationType, Annotation, RangeSet, Range } from "@codemirror/state";
|
|
||||||
import {
|
|
||||||
ViewUpdate,
|
|
||||||
ViewPlugin,
|
|
||||||
Decoration,
|
|
||||||
WidgetType
|
|
||||||
} from "@codemirror/view";
|
|
||||||
|
|
||||||
import type { PluginValue, DecorationSet, EditorView } from "@codemirror/view";
|
|
||||||
|
|
||||||
export class RemoteCursorWidget extends WidgetType {
|
|
||||||
public constructor(
|
|
||||||
private readonly color: string,
|
|
||||||
private readonly name: string
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public toDOM(editor: EditorView): HTMLElement {
|
|
||||||
return editor.contentDOM.createEl(
|
|
||||||
"span",
|
|
||||||
{
|
|
||||||
cls: "selection-caret",
|
|
||||||
attr: {
|
|
||||||
style: `background-color: ${this.color}; border-color: ${this.color}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(span) => {
|
|
||||||
span.createEl("div", {
|
|
||||||
cls: "stick"
|
|
||||||
});
|
|
||||||
span.createEl("div", {
|
|
||||||
cls: "dot"
|
|
||||||
});
|
|
||||||
span.createEl("div", {
|
|
||||||
cls: "info",
|
|
||||||
text: this.name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public eq(other: RemoteCursorWidget): boolean {
|
|
||||||
return other.color === this.color && other.name === this.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
import type { Range } from "@codemirror/state";
|
|
||||||
import { RangeSet, Annotation, AnnotationType } from "@codemirror/state";
|
|
||||||
import { ViewPlugin, Decoration, WidgetType } from "@codemirror/view";
|
|
||||||
|
|
||||||
import type {
|
|
||||||
PluginValue,
|
|
||||||
DecorationSet,
|
|
||||||
EditorView,
|
|
||||||
ViewUpdate
|
|
||||||
} from "@codemirror/view";
|
|
||||||
import { RemoteCursorWidget } from "./remote-cursor-widget";
|
|
||||||
import type { ClientCursors, CursorSpan } from "sync-client";
|
|
||||||
import type { App } from "obsidian";
|
|
||||||
import { MarkdownView } from "obsidian";
|
|
||||||
|
|
||||||
let cursors: {
|
|
||||||
name: string;
|
|
||||||
path: string;
|
|
||||||
span: CursorSpan;
|
|
||||||
}[] = [];
|
|
||||||
|
|
||||||
import { StateEffect } from "@codemirror/state";
|
|
||||||
import { getRandomColor } from "src/utils/get-random-color";
|
|
||||||
|
|
||||||
const forceUpdate = StateEffect.define();
|
|
||||||
|
|
||||||
export class RemoteCursorsPluginValue implements PluginValue {
|
|
||||||
public decorations: DecorationSet = RangeSet.of([]);
|
|
||||||
|
|
||||||
public update(update: ViewUpdate): void {
|
|
||||||
const decorations: Range<Decoration>[] = [];
|
|
||||||
|
|
||||||
cursors.forEach(({ name, span: { start, end } }) => {
|
|
||||||
const color = getRandomColor(name);
|
|
||||||
const startLine = update.view.state.doc.lineAt(start);
|
|
||||||
const endLine = update.view.state.doc.lineAt(end);
|
|
||||||
|
|
||||||
const attributes = {
|
|
||||||
style: `background-color: ${color};`
|
|
||||||
};
|
|
||||||
|
|
||||||
if (startLine.number === endLine.number) {
|
|
||||||
// selected content in a single line.
|
|
||||||
decorations.push({
|
|
||||||
from: start,
|
|
||||||
to: end,
|
|
||||||
value: Decoration.mark({
|
|
||||||
attributes
|
|
||||||
})
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// selected content in multiple lines
|
|
||||||
// first, render text-selection in the first line
|
|
||||||
decorations.push({
|
|
||||||
from: start,
|
|
||||||
to: startLine.from + startLine.length,
|
|
||||||
value: Decoration.mark({
|
|
||||||
attributes
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
// render text-selection in the lines between the first and last line
|
|
||||||
for (let i = startLine.number + 1; i < endLine.number; i++) {
|
|
||||||
const currentLine = update.view.state.doc.line(i);
|
|
||||||
decorations.push({
|
|
||||||
from: currentLine.from,
|
|
||||||
to: currentLine.to,
|
|
||||||
value: Decoration.mark({
|
|
||||||
attributes
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// render text-selection in the last line
|
|
||||||
decorations.push({
|
|
||||||
from: endLine.from,
|
|
||||||
to: end,
|
|
||||||
value: Decoration.mark({
|
|
||||||
attributes
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
decorations.push({
|
|
||||||
from: end,
|
|
||||||
to: end,
|
|
||||||
value: Decoration.widget({
|
|
||||||
side: end - start > 0 ? -1 : 1, // the local cursor should be rendered outside the remote selection
|
|
||||||
block: false,
|
|
||||||
widget: new RemoteCursorWidget(color, name)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.decorations = Decoration.set(decorations, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const remoteCursorsPlugin = ViewPlugin.fromClass(
|
|
||||||
RemoteCursorsPluginValue,
|
|
||||||
{
|
|
||||||
decorations: (v) => v.decorations
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export function setCursors(clients: ClientCursors[], app: App): void {
|
|
||||||
cursors = clients.flatMap((client) => {
|
|
||||||
const clientCursors = client.cursors;
|
|
||||||
return Object.keys(clientCursors).flatMap((path) => {
|
|
||||||
const spans = clientCursors[path];
|
|
||||||
return spans
|
|
||||||
? spans.map((span) => ({
|
|
||||||
name: client.userName,
|
|
||||||
path,
|
|
||||||
span
|
|
||||||
}))
|
|
||||||
: [];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.workspace
|
|
||||||
.getLeavesOfType("markdown")
|
|
||||||
.map((leaf) => leaf.view)
|
|
||||||
.filter((view) => view instanceof MarkdownView)
|
|
||||||
.forEach((view) => {
|
|
||||||
// @ts-expect-error, not typed
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
||||||
const editor = view.editor.cm as EditorView;
|
|
||||||
|
|
||||||
editor.dispatch({
|
|
||||||
effects: [forceUpdate.of(null)]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
.vault-link-sync-status {
|
|
||||||
position: absolute;
|
|
||||||
right: var(--size-4-4);
|
|
||||||
top: var(--size-4-2);
|
|
||||||
opacity: 0.7;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
> span {
|
|
||||||
opacity: 0;
|
|
||||||
position: absolute;
|
|
||||||
min-width: 200px;
|
|
||||||
text-align: right;
|
|
||||||
padding-right: var(--size-2-2);
|
|
||||||
|
|
||||||
top: 50%;
|
|
||||||
left: 0;
|
|
||||||
transform: translateY(-50%) translateX(-100%) translateY(-2px);
|
|
||||||
transition: opacity 200ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
> span {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .icon {
|
|
||||||
line-height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.loading > .icon {
|
|
||||||
animation: spin 2s linear infinite;
|
|
||||||
|
|
||||||
@keyframes spin {
|
|
||||||
0% {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue