Skip to content

Commit

Permalink
changes requested by joethei (#3)
Browse files Browse the repository at this point in the history
* fix: don't detach leaves

* fix: use element.toggleClass

* fix: use setHeader in settings

* refactor: use AbstractInputSuggest

* refactor: remove debounce

* refactor: remove assign-hotkeys setting

* docs: update readme

* chore: update description

* chore: bump version
  • Loading branch information
ycnmhd authored Feb 29, 2024
1 parent 3ebc165 commit 24c4b75
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 375 deletions.
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ An obsidian plugin that extends the functionality of comments and highlights.
![](./docs/media/screenshot.png)

## Features
- Explore comments/highlights of the active file using a sidebar view <a href="https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/sidebar.gif" target="_blank">🎬</a>.
- Create notes from comments/highlights using the editor context menu <a href="https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/notes.gif" target="_blank">🎬</a>.
- Copy comments/highlights of selected files using the file-explorer context menu. <a href="https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/clipboard.gif" target="_blank">🎬</a>.
- Assign custom styles to different types of comments/highlights based on their label (e.g., `<!--title: ...-->`, `<!--todo: ...-->`) <a href="https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/styling.gif" target="_blank">🎬</a>.
- Use a trigger phrase to insert a labeled comment (e.g., `//todo` to insert `<!--todo: -->`) <a href="https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/autocomplete.gif" target="_blank">🎬</a>.
- Explore comments/highlights of the active file in a sidebar view [🎬](https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/sidebar.gif)
- Create notes from comments/highlights using the editor context menu [🎬](https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/notes.gif)
- Copy comments/highlights of selected files using the file-explorer context menu. [🎬](https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/clipboard.gif)
- Assign custom styles to different types of comments/highlights based on their label (e.g., `<!--title: ...-->`, `<!--todo: ...-->`) [🎬](https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/styling.gif)
- Use a trigger phrase to insert a labeled comment (e.g., `//todo` to insert `<!--todo: -->`) [🎬](https://raw.githubusercontent.com/ycnmhd/obsidian-enhanced-annotations/main/docs/media/autocomplete.gif)

## Installation
The plugin is not available in the community plugins store yet.

### BRAT (recommended)
[Quick guide](https://github.com/TfTHacker/obsidian42-brat/tree/ac60154446f64ecfb950fa068a8bc1c14f8bdbbe?tab=readme-ov-file#adding-a-beta-plugin).

### Manual
- Download `main.js`, `styles.css` and `manifest.json` from [releases](https://github.com/ycnmhd/obsidian-enhanced-annotations/releases) to `vault/.obsidian/plugins/enhanced-annotations/`.
- Refresh the `community plugins list` in `Obsidian`, and enable the `Enhanced Annotations` plugin.


4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "enhanced-annotations",
"name": "Enhanced Annotations",
"version": "0.1.1",
"version": "0.1.2",
"minAppVersion": "0.15.0",
"description": "Adds features to comments and highlights.",
"description": "Add a sidebar view for comments and highlights.",
"author": "ycnmhd",
"isDesktopOnly": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enhanced-annotations",
"version": "0.1.1",
"version": "0.1.2",
"description": "",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
5 changes: 1 addition & 4 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,11 @@ export const addInsertCommentCommands = (plugin: EnhancedAnnotations) => {
},
];

for (const { name, hotkeys, editorCallback } of commands) {
for (const { name, editorCallback } of commands) {
plugin.addCommand({
id: slugify(name),
editorCallback,
name: name,
hotkeys: plugin.settings.getValue().commands.assignHotkeys
? hotkeys
: undefined,
});
}
};
17 changes: 0 additions & 17 deletions src/helpers/debounce.ts

This file was deleted.

20 changes: 13 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ export default class LabeledAnnotations extends Plugin {
async activateView() {
this.app.workspace.detachLeavesOfType(SIDEBAR_OUTLINE_VIEW_TYPE);

await this.app.workspace.getRightLeaf(false).setViewState({
type: SIDEBAR_OUTLINE_VIEW_TYPE,
active: true,
});

this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(SIDEBAR_OUTLINE_VIEW_TYPE)[0],
const leaves = this.app.workspace.getLeavesOfType(
SIDEBAR_OUTLINE_VIEW_TYPE,
);
if (leaves.length === 0) {
await this.app.workspace.getRightLeaf(false).setViewState({
type: SIDEBAR_OUTLINE_VIEW_TYPE,
active: true,
});
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(
SIDEBAR_OUTLINE_VIEW_TYPE,
)[0],
);
}
}

registerSubscription(...callback: (() => void)[]) {
Expand Down
4 changes: 0 additions & 4 deletions src/settings/default-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export const DEFAULT_SETTINGS = (): Settings => ({
},
defaultPalette: 'bright',
},
commands: {
enableLabelCommands: false,
assignHotkeys: false,
},
outline: {
fontSize: 12,
showLabelsFilter: false,
Expand Down
5 changes: 0 additions & 5 deletions src/settings/settings-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ export type SettingsActions =
| {
type: 'TOGGLE_TRUNCATE_FILE_NAME';
}
| {
type: 'TOGGLE_ASSIGN_HOTKEYS';
}
| { type: 'SET_DEFAULT_PALETTE'; payload: { palette: DefaultPalette } };

const updateState = (store: Settings, action: SettingsActions) => {
Expand Down Expand Up @@ -229,8 +226,6 @@ const updateState = (store: Settings, action: SettingsActions) => {
store.clipboard.templates[name] = template;
} else if (action.type === 'TOGGLE_TRUNCATE_FILE_NAME') {
store.notes.truncateFileName = !store.notes.truncateFileName;
} else if (action.type === 'TOGGLE_ASSIGN_HOTKEYS') {
store.commands.assignHotkeys = !store.commands.assignHotkeys;
} else if (action.type === 'SET_DEFAULT_PALETTE') {
store.decoration.defaultPalette = action.payload.palette;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Setting } from 'obsidian';
import LabeledAnnotations from '../../../main';
import { l } from '../../../lang/lang';
import { CommentFormat } from '../../settings-type';
import { settingsHeader } from '../../../status-bar/helpers/class-names';

type Props = {
containerEl: HTMLElement;
plugin: LabeledAnnotations;
};
export const AutoSuggestSettings = ({ plugin, containerEl }: Props) => {
containerEl.createEl('h3', { text: l.SETTINGS_AUTO_SUGGEST_TITLE });
new Setting(containerEl)
.setName(l.SETTINGS_AUTO_SUGGEST_TITLE)
.setHeading()
.settingEl.addClass(settingsHeader);
const settings = plugin.settings.getValue();
new Setting(containerEl)
.setName(l.SETTINGS_AUTO_SUGGEST_ENABLE)
Expand Down
6 changes: 5 additions & 1 deletion src/settings/settings-tab/components/clipboard-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
copiedAnnotationsTemplates,
copiedAnnotationsVariables,
} from '../../../clipboard/helpers/annotations-to-text';
import { settingsHeader } from '../../../status-bar/helpers/class-names';

type Props = {
containerEl: HTMLElement;
Expand All @@ -16,7 +17,10 @@ export const ClipboardSettings = ({ plugin, containerEl }: Props) => {
const settings = plugin.settings;
const render = () => {
containerEl.empty();
containerEl.createEl('h3', { text: l.SETTINGS_CLIPBOARD_TITLE });
new Setting(containerEl)
.setName(l.SETTINGS_CLIPBOARD_TITLE)
.setHeading()
.settingEl.addClass(settingsHeader);
for (const Key of ['Front', 'Header', 'Comment', 'Highlight']) {
const key = Key.toLowerCase() as ClipboardTemplateSection;

Expand Down
22 changes: 0 additions & 22 deletions src/settings/settings-tab/components/commands-settings.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { l } from '../../../../lang/lang';
import { Setting } from 'obsidian';
import { TagSettings } from './components/tag-settings';
import { DefaultPalette } from '../../../settings-type';
import { settingsHeader } from '../../../../status-bar/helpers/class-names';

type Props = {
containerEl: HTMLElement;
plugin: LabeledAnnotations;
};
export const LabelsSettings = ({ plugin, containerEl }: Props) => {
containerEl.createEl('h3', { text: l.SETTINGS_LABELS_STYLES_TITLE });
new Setting(containerEl)
.setName(l.SETTINGS_LABELS_STYLES_TITLE)
.setHeading()
.settingEl.addClass(settingsHeader);
const settings = plugin.settings.getValue();
const render = () => {
containerEl.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,44 @@
/* credit: https://github.com/liamcain/obsidian-periodic-notes/blob/10fa35874d92750508967d4f1e58b3fa0eb87996/src/ui/file-suggest.ts#L1 */
import { TAbstractFile, TFile, TFolder } from "obsidian";
import { TextInputSuggest } from "./text-input-suggest";

export class FileSuggest extends TextInputSuggest<TFile> {
getSuggestions(inputStr: string): TFile[] {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const files: TFile[] = [];
const lowerCaseInputStr = inputStr.toLowerCase();

abstractFiles.forEach((file: TAbstractFile) => {
if (
file instanceof TFile &&
file.extension === "md" &&
file.path.toLowerCase().contains(lowerCaseInputStr)
) {
files.push(file);
}
});

return files;
}

renderSuggestion(file: TFile, el: HTMLElement): void {
el.setText(file.path);
}

selectSuggestion(file: TFile): void {
this.inputEl.value = file.path;
this.inputEl.trigger("input");
this.close();
}
}

export class FolderSuggest extends TextInputSuggest<TFolder> {
getSuggestions(inputStr: string): TFolder[] {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const folders: TFolder[] = [];
const lowerCaseInputStr = inputStr.toLowerCase();

abstractFiles.forEach((folder: TAbstractFile) => {
if (
folder instanceof TFolder &&
folder.path.toLowerCase().contains(lowerCaseInputStr)
) {
folders.push(folder);
}
});

return folders;
}

renderSuggestion(file: TFolder, el: HTMLElement): void {
el.setText(file.path);
}

selectSuggestion(file: TFolder): void {
this.inputEl.value = file.path;
this.inputEl.trigger("input");
this.close();
}
import { AbstractInputSuggest, App, TFolder } from 'obsidian';

export class FolderSuggest extends AbstractInputSuggest<string> {
content: Set<string>;

constructor(
app: App,
private inputEl: HTMLInputElement,
private onSelectCallback: (value: string) => void,
) {
super(app, inputEl);
this.content = this.loadContent();
}

loadContent(): Set<string> {
const abstractFiles = this.app.vault.getAllLoadedFiles();
const folders: Set<string> = new Set();

for (const folder of abstractFiles) {
if (folder instanceof TFolder) {
folders.add(folder.path);
}
}

return folders;
}

getSuggestions(inputStr: string): string[] {
const lowerCaseInputStr = inputStr.toLocaleLowerCase();
return [...this.content].filter((content) =>
content.toLocaleLowerCase().contains(lowerCaseInputStr),
);
}
renderSuggestion(content: string, el: HTMLElement): void {
el.setText(content);
}

selectSuggestion(content: string): void {
this.onSelectCallback(content);
this.inputEl.value = content;
this.inputEl.blur();
this.close();
}
}
Loading

0 comments on commit 24c4b75

Please sign in to comment.