Skip to content

Commit

Permalink
Added command insert-ordinal-numbering, prepared files for release …
Browse files Browse the repository at this point in the history
…2.0.0
  • Loading branch information
KrazyManJ committed May 5, 2023
1 parent 85f9ff0 commit e7acd74
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 178 deletions.
115 changes: 75 additions & 40 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "keyshots",
"name": "Keyshots",
"version": "1.5.0",
"version": "2.0.0",
"minAppVersion": "0.15.0",
"description": "Adds classic hotkey/shortcuts commands from popular IDEs like Visual Studio Code or JetBrains Family.",
"author": "KrazyManJ",
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-keyshots",
"version": "1.5.0",
"version": "2.0.0",
"description": "",
"main": "main.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "",
"author": "KrazyManJ",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
Expand Down
7 changes: 7 additions & 0 deletions src/classes/editor-position-manipulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ export default class EditorPositionManipulator implements EditorPosition, JavaLi
return this
}

setPos(line: number, ch: number): this {
this.line = line
this.ch = ch
return this
}

toOffset(): number {
return this.editor.posToOffset(this)
}

static documentStart(editor: Editor): EditorPositionManipulator {
return new EditorPositionManipulator({ch: 0, line: 0}, editor)
}

}
104 changes: 55 additions & 49 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ export const COMMANDS = (plugin: KeyshotsPlugin, map: KeyshotsMap): Command[] =>
* =======================================================================================
*/
{
id: 'toggle-readable-length',
name: "Toggle readable line length (setting)",
hotkeys: map.toggle_readable_length,
id: 'switch-readable-length-setting',
name: "Switch 'readable line length' setting",
hotkeys: map.switch_readable_length_setting,
callback: () => functions.flipBooleanSetting(plugin.app, 'readableLineLength')
},
{
id: 'toggle-line-numbers',
name: "Toggle line numbers (setting)",
hotkeys: map.toggle_line_numbers,
id: 'switch-line-numbers-setting',
name: "Switch 'line numbers' setting",
hotkeys: map.switch_line_numbers_setting,
callback: () => functions.flipBooleanSetting(plugin.app, 'showLineNumber')
},
{
id: 'toggle-inline-title',
name: "Toggle inline title (setting)",
hotkeys: map.toggle_inline_title,
id: 'switch-inline-title-setting',
name: "Switch 'inline title' setting",
hotkeys: map.switch_inline_title_setting,
callback: () => functions.flipBooleanSetting(plugin.app, 'showInlineTitle')
},
/*
Expand All @@ -39,20 +39,20 @@ export const COMMANDS = (plugin: KeyshotsPlugin, map: KeyshotsMap): Command[] =>
*/
{
id: 'change-keyshots-preset',
name: "Change Keyshots Preset",
hotkeys: map.change_hotkeys_presets,
name: "Change Keyshots preset",
hotkeys: map.change_keyshots_preset,
callback: () => new IDEPresetModal(plugin).open()
},
{
id: 'toggle-keyshots-case-sensitivity',
name: "Toggle Keyshots case sensitivity",
hotkeys: map.toggle_keyshots_case_sensitivity,
id: 'switch-keyshots-case-sensitivity',
name: "Switch Keyshots case sensitivity",
hotkeys: map.switch_keyshots_case_sensitivity,
callback: () => functions.toggleCaseSensitivity(plugin)
},
{
id: 'open-keyshots-settings',
name: "Open Keyshots settings",
hotkeys: map.open_keyshots_settings,
id: 'open-keyshots-settings-tab',
name: "Open Keyshots settings tab",
hotkeys: map.open_keyshots_settings_tab,
callback: () => functions.openKeyshotsSettings(app)
},
/*
Expand Down Expand Up @@ -145,17 +145,17 @@ export const COMMANDS = (plugin: KeyshotsPlugin, map: KeyshotsMap): Command[] =>
* =======================================================================================
*/
{
id: 'add-carets-up',
id: 'add-caret-up',
name: 'Add caret cursor up',
repeatable: true,
hotkeys: map.add_carets_up,
hotkeys: map.add_caret_up,
editorCallback: (editor) => functions.addCarets(editor, VerticalDirection.UP, 0)
},
{
id: 'add-carets-down',
id: 'add-caret-down',
name: 'Add caret cursor down',
repeatable: true,
hotkeys: map.add_carets_down,
hotkeys: map.add_caret_down,
editorCallback: (editor) => functions.addCarets(editor, VerticalDirection.DOWN, editor.lineCount())
},
{
Expand Down Expand Up @@ -188,47 +188,47 @@ export const COMMANDS = (plugin: KeyshotsPlugin, map: KeyshotsMap): Command[] =>
editorCallback: (editor) => functions.replaceSelections(editor, (s) => s.trim())
},
{
id: 'transform-from-to-snake-case',
name: "Transform selections from / to Snakecase",
hotkeys: map.transform_from_to_snakecase,
id: 'toggle-snake-case',
name: "Toggle selections snakecase",
hotkeys: map.toggle_snakecase,
editorCallback: (editor) => functions.convertOneToOtherChars(editor, " ", "_")
},
{
id: 'transform-from-to-kebab-case',
name: "Transform selections from / to Kebabcase",
hotkeys: map.transform_from_to_kebabcase,
id: 'toggle-kebab-case',
name: "Toggle selections kebabcase",
hotkeys: map.toggle_kebabcase,
editorCallback: (editor) => functions.convertOneToOtherChars(editor, " ", "-")
},
{
id: 'encode-or-decode-uri',
name: "Encode / Decode URI selections",
hotkeys: map.encode_or_decode_uri,
id: 'toggle-uri-encoded-or-decoded',
name: "Toggle selections URI encoded/decoded string",
hotkeys: map.toggle_uri_encoded_or_decoded,
editorCallback: (editor) => functions.convertURI(editor)
},
{
id: 'transform-selections-to-lowercase',
name: "Transform selections to Lowercase",
name: "Transform selections to lowercase",
hotkeys: map.transform_selections_to_lowercase,
editorCallback: (editor) => functions.replaceSelections(editor, (s) => s.toLowerCase())
},
{
id: 'transform-selections-to-uppercase',
name: "Transform selections to Uppercase",
name: "Transform selections to uppercase",
hotkeys: map.transform_selections_to_uppercase,
editorCallback: (editor) => functions.replaceSelections(editor, (s) => s.toUpperCase())
},
{
id: 'transform-selections-to-titlecase',
name: "Transform selections to Titlecase (Capitalize)",
name: "Transform selections to titlecase (capitalize)",
hotkeys: map.transform_selections_to_titlecase,
editorCallback: (editor) => functions.replaceSelections(editor, (s) =>
s.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase())
)
},
{
id: 'toggle-case',
id: 'toggle-case-jetbrains',
name: "Toggle case (JetBrains)",
hotkeys: map.toggle_case,
hotkeys: map.toggle_case_jetbrains,
editorCallback: (editor) => functions.replaceSelections(editor, (str) => str === str.toLowerCase() ? str.toUpperCase() : str.toLowerCase())
},
/*
Expand All @@ -238,71 +238,77 @@ export const COMMANDS = (plugin: KeyshotsPlugin, map: KeyshotsMap): Command[] =>
*/
{
id: 'multi-toggle-bold',
name: "Multi Toggle Bold",
name: "Multi-toggle bold",
hotkeys: map.multi_toggle_bold,
editorCallback: (editor) => functions.surroundWithChars(editor, "**")
},
{
id: 'multi-toggle-italic',
name: "Multi Toggle Italic",
name: "Multi-toggle italic",
hotkeys: map.multi_toggle_italic,
editorCallback: (editor) => functions.surroundWithChars(editor, "*")
},
{
id: 'multi-toggle-code',
name: "Multi Toggle Code",
name: "Multi-toggle code",
hotkeys: map.multi_toggle_code,
editorCallback: (editor) => functions.surroundWithChars(editor, "``")
},
{
id: 'multi-toggle-highlight',
name: "Multi Toggle Highlight",
name: "Multi-toggle highlight",
hotkeys: map.multi_toggle_highlight,
editorCallback: (editor) => functions.surroundWithChars(editor, "==")
},
{
id: 'multi-toggle-comment',
name: "Multi Toggle Comment",
name: "Multi-toggle comment",
hotkeys: map.multi_toggle_comment,
editorCallback: (editor) => functions.surroundWithChars(editor, "%%")
},
{
id: 'multi-toggle-strikethrough',
name: "Multi Toggle Strikethrough",
name: "Multi-toggle strikethrough",
hotkeys: map.multi_toggle_strikethrough,
editorCallback: (editor) => functions.surroundWithChars(editor, "~~")
},
{
id: 'toggle-underline',
name: "Toggle Underline",
name: "Toggle underline",
hotkeys: map.toggle_underline,
editorCallback: (editor) => functions.surroundWithChars(editor, "<u>", "</u>")
},
{
id: 'toggle-keybinding',
name: "Toggle Keybinding tag (<kbd>)",
hotkeys: map.toggle_keybinding,
id: 'toggle-keyboard-input',
name: "Toggle keyboard input (<kbd>)",
hotkeys: map.toggle_keyboard_input,
editorCallback: (editor) => functions.surroundWithChars(editor, "<kbd>", "</kbd>")
},
{
id: 'insert-code-block',
name: "Insert Code Block",
hotkeys: map.insert_codeblock,
name: "Insert code block",
hotkeys: map.insert_code_block,
editorCallback: (editor) => new CodeBlockModal(
plugin, (item) => functions.insertCodeBlock(editor, item)
).open()
},
{
id: 'insert-ordinal-numbering',
name: "Insert ordinal numbering",
hotkeys: map.insert_ordinal_numbering,
editorCallback: (editor) => functions.insertOrdinalNumbering(editor)
},
/*
* =======================================================================================
* OTHERS
* =======================================================================================
*/
{
id: 'open-dev-tools',
name: "Open Developer Tools",
name: "Open developer tools",
hotkeys: map.open_dev_tools,
callback: () => electron.remote.getCurrentWindow().webContents.openDevTools()
}
},
]

declare interface PluginConditionalObject<T> {
Expand Down
15 changes: 12 additions & 3 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export function addCarets(editor: Editor, direction: VerticalDirection, border:
selections.splice(mainIndex, 1)
selections.unshift(main)
editor.setSelections(selections)
editor.scrollIntoView(newSel.anchor.clone().movePos(direction * 2, 0).asEditorRange())
editor.scrollIntoView(newSel.anchor.clone().setPos(
Math.min(editor.lineCount()-1,newSel.anchor.line+direction * 2), newSel.anchor.ch
).asEditorRange())
}

export function insertLine(editor: Editor, direction: VerticalDirection) {
Expand Down Expand Up @@ -280,7 +282,14 @@ export function addCaretsViaDoubleKey(plugin: KeyshotsPlugin, ev: KeyboardEvent)
)
}

export function runCommandById(plugin: KeyshotsPlugin, id: string, notAvailableCallback: () => void) {
if (plugin.app.internalPlugins.plugins[id.split(":")[0]]) plugin.app.commands.executeCommandById(id)
export function runCommandById(keyshotsPlugin: KeyshotsPlugin, id: string, notAvailableCallback: () => void) {
const plugin = keyshotsPlugin.app.internalPlugins.plugins[id.split(":")[0]]
if (plugin && plugin.enabled) keyshotsPlugin.app.commands.executeCommandById(id)
else notAvailableCallback()
}

export function insertOrdinalNumbering(editor: Editor) {
SelectionsProcessing.selectionsProcessor(editor, undefined, (sel,index) => {
return sel.replaceText((index+1).toString(),true)
})
}
Loading

0 comments on commit e7acd74

Please sign in to comment.