OSDN Git Service

Initial release
authorpluginfan <pluginfan@suremail.info>
Mon, 28 Mar 2016 08:56:42 +0000 (11:56 +0300)
committerpluginfan <pluginfan@suremail.info>
Mon, 28 Mar 2016 08:56:42 +0000 (11:56 +0300)
Move Caret To Word End/NEWS [new file with mode: 0644]
Move Caret To Word End/README [new file with mode: 0644]
Move Caret To Word End/TODO [new file with mode: 0644]
Move Caret To Word End/plugin.groovy [new file with mode: 0644]
README [new file with mode: 0644]

diff --git a/Move Caret To Word End/NEWS b/Move Caret To Word End/NEWS
new file mode 100644 (file)
index 0000000..5854161
--- /dev/null
@@ -0,0 +1,3 @@
+Version 0.0 -- March 2016
+~~~~~~~~~~~~~~~~~~~~~~~~~
+Initial release.
diff --git a/Move Caret To Word End/README b/Move Caret To Word End/README
new file mode 100644 (file)
index 0000000..84e4ad2
--- /dev/null
@@ -0,0 +1,12 @@
+Move Caret to Word End
+~~~~~~~~~~~~~~~~~~~~~~
+
+Moves all carets to the closes word end.
+
+Action:
+* Move Caret to Next Word End
+* Move Caret to Previous Word End
+
+Shortcut:
+* Ctrl+NumPad 6 -- Move Caret to Next Word End
+* Ctrl+NumPad 4 -- Move Caret to Previous Word End
diff --git a/Move Caret To Word End/TODO b/Move Caret To Word End/TODO
new file mode 100644 (file)
index 0000000..63af2a2
--- /dev/null
@@ -0,0 +1,2 @@
+* Make Shift+movement select text / extend selection.
+* Find IntelliJ IDEA's own word start detection rule and use a similar one.
diff --git a/Move Caret To Word End/plugin.groovy b/Move Caret To Word End/plugin.groovy
new file mode 100644 (file)
index 0000000..5d496de
--- /dev/null
@@ -0,0 +1,55 @@
+// plugin  Move Caret To Word End
+// version 0.0
+// release March 2016
+// author  Plugin Fan
+// license GPL v 3.0
+
+// Moves all carets to the closest word end :
+//     - Ctrl-NumPad6 - Move Caret to Next Word End
+//     - Ctrl-NumPad4 - Move Caret to Previous Word End
+//
+// When moving word-by-word, the IDE's builtin algorithm stops on word starts. Often you can reach the word end only by
+// moving one word further then moving a couple of characters back. But this may not be an option when using multiple
+// carets and there are different amounts of separators between the words.
+
+import com.intellij.openapi.actionSystem.AnActionEvent
+import static liveplugin.PluginUtil.*
+
+// perform the caret movement
+def moveCaretToWordEnd(event, direction)
+{
+    // direction specific movement parameters
+    def search = [
+        'forward':  ['step': +1, 'check':  0, 'match': true ],
+        'backward': ['step': -1, 'check': -1, 'match': false],
+    ][direction]
+
+    runDocumentWriteAction(event.project) {
+        currentEditorIn(event.project).with {
+            caretModel.getAllCarets().each { caret ->
+                def offset = caret.offset
+                def text = document.getCharsSequence()
+                def size = text.size()
+
+                // move to closest position from where the closest word end becomes visible
+                while (offset + search.check >= 0 && offset + search.check < size && Character.isLetterOrDigit(text.charAt(offset + search.check)) != search.match)
+                    offset += search.step
+
+                // move to closest word end
+                while (offset + search.check >= 0 && offset + search.check < size && Character.isLetterOrDigit(text.charAt(offset + search.check)) == search.match)
+                    offset += search.step
+
+                // place the caret into the new position
+                caret.moveToOffset(offset)
+            }
+        }
+    }
+}
+
+registerAction('Move Caret to Next Word End', 'ctrl NUMPAD6') { AnActionEvent event ->
+    moveCaretToWordEnd(event, 'forward')
+}
+
+registerAction('Move Caret to Previous Word End', 'ctrl NUMPAD4') { AnActionEvent event ->
+    moveCaretToWordEnd(event, 'backward')
+}
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..2cadccc
--- /dev/null
+++ b/README
@@ -0,0 +1,6 @@
+IntelliJ IDEA LivePlugin Plugin collection
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Plugins written in Groovy <http://groovy-lang.org/> script for IntelliJ IDEA <http://jetbrains.com/idea/> based IDE's that can be enhanced through LivePlugin <https://github.com/dkandalov/live-plugin> plugin connector.
+
+* Move Caret to Word End -- Moves all carets to the closes word end.