Adds go to source feature

This commit is contained in:
Simon Schödler 2023-05-06 15:34:38 +02:00
parent f88297dc3c
commit 989b3b9d8c
4 changed files with 30 additions and 6 deletions

5
DEV.md
View file

@ -3,13 +3,14 @@
## Roadmap
- [x] General UX Improvement
- [ ] Add "Goto Source" action on suggestions
- [x] Add "Goto Source" action on suggestions
- [x] Fix occurrences hint not being updated when new occurrences are found
## Refactors
- [x] Refactor handling / updating of `TreeItem`s. Use a reactive approach instead of manually updating the tree.
- [ ] Refactor `Editor.getWordLookup()` there has to be a better way of retrieving plain-text from an `Editor` (Without manually removing MD syntax)
- [ ] Refactor `Editor.getWordLookup()` there has to be a better way of retrieving plain-text from an `Editor` (Without manually removing MD syntax) (Maybe a code mirror plugin?)
- [ ] Minimally stem words before matching them to cache items
## Releasing new releases

View file

@ -10,9 +10,10 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { ButtonComponent, Editor, EditorPosition } from 'obsidian';
import { ButtonComponent, Editor, EditorPosition, MarkdownView } from 'obsidian';
import { Match, Occurrence, Suggestion } from 'src/model/suggestion';
import { CacheMatch } from 'src/services/indexingService';
import { CrossbowLoggingService } from 'src/services/loggingService';
import { CrossbowSettingsService } from 'src/services/settingsService';
import { TreeItem, TreeItemButtonIcon, TreeItemLeaf } from 'src/view/treeItem';
import { CrossbowView } from 'src/view/view';
@ -153,7 +154,19 @@ export class CrossbowViewController {
// Go to source action
matchTreeItem.addButton('Go To Source', TreeItemButtonIcon.Search, () => {
console.warn("🏹: 'Go To Source' is not yet implemented");
const leaf = app.workspace.getLeaf(true);
app.workspace.setActiveLeaf(leaf);
leaf.openFile(match.cacheMatch.file).then(() => {
if (leaf.view instanceof MarkdownView) {
if (match.cacheMatch.item?.position) {
const { line, col } = match.cacheMatch.item.position.start
leaf.view.editor.setCursor(line, col);
}
}
else {
CrossbowLoggingService.forceLog('warn', 'Could not go to source, not a markdown file');
}
});
});
matchTreeItem.addTextSuffix(match.cacheMatch.type);

View file

@ -15,7 +15,17 @@ import { CrossbowSettingsService } from './settingsService';
export class CrossbowLoggingService {
public constructor(private readonly settingsService: CrossbowSettingsService) {}
private static LOGGER_PREFIX = '🏹: ';
public debugLog(message: string): void {
this.settingsService.getSettings().useLogging && console.log(`🏹: ${message}`);
this.settingsService.getSettings().useLogging && console.log(CrossbowLoggingService.LOGGER_PREFIX + message);
}
public debugWarn(message: string): void {
this.settingsService.getSettings().useLogging && console.warn(CrossbowLoggingService.LOGGER_PREFIX + message);
}
public static forceLog(type: 'warn' | 'log', message: string): void {
console[type](CrossbowLoggingService.LOGGER_PREFIX + message);
}
}

View file

@ -10,7 +10,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { App, PluginSettingTab, Setting } from 'obsidian';
import { App, ButtonComponent, PluginSettingTab, Setting } from 'obsidian';
import CrossbowPlugin from './main';
import { CrossbowPluginSettings, CrossbowSettingsService } from './services/settingsService';