Skip to content

Commit

Permalink
improved stops navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ArianaKhit committed May 12, 2022
1 parent b836976 commit 95787c5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
25 changes: 11 additions & 14 deletions main.js

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
App,
Editor,
MarkdownView,
Notice,
// Notice,
Plugin,
PluginSettingTab,
Setting,
Expand Down Expand Up @@ -124,15 +124,15 @@ export default class TextSnippets extends Plugin {
findSnippet(editor : CodeMirror.Editor, cursorOrig : CodeMirror.Position, cursor : CodeMirror.Position) : string {
var selectedText = this.getSelectedText(editor);
var wordDelimiters = Array.from(this.settings.wordDelimiters);
var selectedWoSpaces = selectedText.split(' ').join('');
var selectedWoSpaces = '' + selectedText.split(' ').join('');
var newStr = "";

if (selectedWoSpaces == '' || wordDelimiters.indexOf(selectedWoSpaces[0]) >= 0 && cursorOrig.ch == cursor.ch) {
editor.execCommand('goWordLeft');
editor.execCommand('goWordLeft');
selectedText = this.getSelectedText(editor);
var cursor = editor.getCursor('from');
}
// without this finds next stop everywhere in file
// if (selectedWoSpaces == '' || (selectedWoSpaces.length > 0 && wordDelimiters.indexOf(selectedWoSpaces[0]) >= 0 && cursorOrig.ch == cursor.ch)) {
// editor.execCommand('goWordLeft');
// editor.execCommand('goWordLeft');
// selectedText = this.getSelectedText(editor);
// var cursor = editor.getCursor('from');
// }

var i;
var snippets = this.settings.snippets;
Expand Down Expand Up @@ -180,7 +180,6 @@ export default class TextSnippets extends Plugin {


insertSnippet(key : string = '', snippetStartpos : CodeMirror.Position = {ch:-1, line:-1}): boolean {
// new Notice('insert snippet');
let activeLeaf: any = this.app.workspace.activeLeaf;
let editor = activeLeaf.view.sourceMode.cmEditor;
// let editor = activeLeaf.view.editor;
Expand All @@ -207,13 +206,12 @@ export default class TextSnippets extends Plugin {
(key == 'Space' && (cursorOrig.ch != endCursor.ch || cursorOrig.line != endCursor.line)) ) {
if (wasSelection == false) {
editor.getDoc().setSelection(cursorOrig, cursorOrig);
// new Notice('replace');
}
if (key == 'Space') return false;
if (newStr == "") {
editor.setCursor(cursorOrig);
return this.nextStop();
}
}
}

//find end position
Expand All @@ -223,7 +221,7 @@ export default class TextSnippets extends Plugin {
if (newStr.indexOf(pasteSymbol) != -1) snippetStartpos = cursor;

editor.replaceSelection(newStr);
// new Notice('replaced?');


if (stopFound) {
editor.setCursor({
Expand Down Expand Up @@ -255,8 +253,7 @@ export default class TextSnippets extends Plugin {
});
}

handleKeyDown (cm: CodeMirror.Editor, event: KeyboardEvent): void {
// new Notice(event.key);
handleKeyDown (cm: CodeMirror.Editor, event: KeyboardEvent): void {
if ((event.key == 'Tab' && this.settings.useTab) || (event.code == 'Space' && this.settings.useSpace)) {
this.SnippetOnTrigger(event.code, true);
}
Expand All @@ -278,7 +275,6 @@ export default class TextSnippets extends Plugin {
}
}
}


if (cursorSt.ch >=0 && cursorSt.line >= 0) { //paste text from clipboard
var cursorOrig = cm.getCursor();
Expand All @@ -297,7 +293,7 @@ export default class TextSnippets extends Plugin {
}
return true;
}
return false;
return this.nextStop();
}

nextStop(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "text-snippets-obsidian",
"name": "Text Snippets",
"description": "Allows you to replace text templates for faster typing, create your own.",
"version": "0.1.0",
"description": "Allows you to replace text templates for faster typing, create your own, expand text shortcuts.",
"version": "0.1.1",
"author": "Ariana Khitrova",
"authorUrl": "",
"isDesktopOnly": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "text-snippets-obsidian",
"version": "0.0.6",
"version": "0.1.1",
"description": "Plugin for using snippets for for faster typing",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 95787c5

Please sign in to comment.