Skip to content

Commit 54bc7cc

Browse files
committed
added cleanSelected hotkey
1 parent 401e540 commit 54bc7cc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main.ts

+17
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export default class HotkeysPlus extends Plugin {
6262
name: "Duplicate the current line or selected lines",
6363
callback: () => this.duplicateLines(),
6464
});
65+
this.addCommand({
66+
id: "clean-selected",
67+
name: "Removes new line characters and html elements",
68+
callback: () => this.cleanSelected(),
69+
});
6570

6671
this.addCommand({
6772
id: 'insert-line-above',
@@ -109,6 +114,18 @@ export default class HotkeysPlus extends Plugin {
109114
var newString = selectedText.content + "\n";
110115
editor.replaceRange(newString, selectedText.start, selectedText.start);
111116
}
117+
cleanSelected() {
118+
var activeLeaf: any = this.app.workspace.activeLeaf;
119+
var editor = activeLeaf.view.sourceMode.cmEditor;
120+
var selectedText = this.getSelectedText(editor);
121+
// removing new line chars
122+
var newString = selectedText.content.trim().replace(/(\r\n|\n|\r)/gm, ' ');
123+
//removing html
124+
newString = newString.replace(/<\/?\w+\/?>/gm, ' ');
125+
// removing access white space
126+
newString = newString.replace(/ +/gm, ' ');
127+
editor.replaceRange(newString, selectedText.start, selectedText.end);
128+
}
112129

113130
onunload() {
114131
console.log("Unloading Hotkeys++ plugin");

0 commit comments

Comments
 (0)