diff --git a/annotation-processors/build.gradle.kts b/annotation-processors/build.gradle.kts index 1c0282df7f..3a8f1226c2 100644 --- a/annotation-processors/build.gradle.kts +++ b/annotation-processors/build.gradle.kts @@ -23,7 +23,7 @@ repositories { dependencies { compileOnly("com.google.devtools.ksp:symbol-processing-api:1.9.21-1.0.15") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$kotlinxSerializationVersion") { - // kotlin stdlib is provided by IJ, so there is no need to include it into the distribution + // kotlin stdlib is provided by IJ, so there is no need to include it into the exclude("org.jetbrains.kotlin", "kotlin-stdlib") exclude("org.jetbrains.kotlin", "kotlin-stdlib-common") } diff --git a/src/main/java/com/maddyhome/idea/vim/package-info.java b/src/main/java/com/maddyhome/idea/vim/package-info.java index 513e286bcc..3ab31bc70b 100644 --- a/src/main/java/com/maddyhome/idea/vim/package-info.java +++ b/src/main/java/com/maddyhome/idea/vim/package-info.java @@ -428,6 +428,7 @@ * |gu| {@link com.maddyhome.idea.vim.action.change.change.ChangeCaseLowerMotionAction} * |gv| {@link com.maddyhome.idea.vim.action.motion.visual.VisualSelectPreviousAction} * |gw| TO BE IMPLEMENTED + * |gx| {@link com.maddyhome.idea.vim.action.motion.search.GotoUrlAction} * |g@| {@link com.maddyhome.idea.vim.action.change.OperatorAction} * |g~| {@link com.maddyhome.idea.vim.action.change.change.ChangeCaseToggleMotionAction} * |g| TO BE IMPLEMENTED diff --git a/src/main/resources/META-INF/includes/VimActions.xml b/src/main/resources/META-INF/includes/VimActions.xml index 8e6889bc52..f29d7bb07e 100644 --- a/src/main/resources/META-INF/includes/VimActions.xml +++ b/src/main/resources/META-INF/includes/VimActions.xml @@ -315,6 +315,7 @@ + diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/motion/search/GotoUrlAction.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/motion/search/GotoUrlAction.kt new file mode 100644 index 0000000000..96799b669d --- /dev/null +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/motion/search/GotoUrlAction.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2003-2023 The IdeaVim authors + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE.txt file or at + * https://opensource.org/licenses/MIT. + */ +package com.maddyhome.idea.vim.action.motion.search + +import com.intellij.vim.annotations.CommandOrMotion +import com.intellij.vim.annotations.Mode +import com.maddyhome.idea.vim.api.ExecutionContext +import com.maddyhome.idea.vim.api.VimEditor +import com.maddyhome.idea.vim.api.injector +import com.maddyhome.idea.vim.command.Command +import com.maddyhome.idea.vim.command.CommandFlags +import com.maddyhome.idea.vim.command.OperatorArguments +import com.maddyhome.idea.vim.diagnostic.vimLogger +import com.maddyhome.idea.vim.handler.VimActionHandler +import com.maddyhome.idea.vim.helper.enumSetOf +import com.maddyhome.idea.vim.helper.vimStateMachine +import com.maddyhome.idea.vim.macro.VimMacroBase.Companion.logger +import java.util.* +import java.util.concurrent.Future +import java.util.regex.Pattern + +@CommandOrMotion(keys = ["gx"], modes = [Mode.NORMAL, Mode.VISUAL]) +public class GotoUrlAction : VimActionHandler.SingleExecution() { + override val type: Command.Type = Command.Type.OTHER_READONLY + private val URL_REGEX = "^((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?$" + private val pattern = Pattern.compile(URL_REGEX); + + override fun execute( + editor: VimEditor, + context: ExecutionContext, + cmd: Command, + operatorArguments: OperatorArguments, + ): Boolean { + val wordUnderCursor = exactWordUnderCursor(editor); + logger.info("word: $wordUnderCursor") + if(!isValidUrl(wordUnderCursor)){ + logger.info("word $wordUnderCursor in not url") + return false; + } + injector.jumpService.saveJumpLocation(editor) + injector.actionExecutor.executeAction("GotoDeclaration", context) + return true + } + + private fun exactWordUnderCursor(editor: VimEditor): String { + var col = editor.currentCaret().vimLastColumn; + var line = editor.getLineText(editor.currentCaret().vimLine - 1); + if(line.isBlank() || line.get(col).isWhitespace()){ + return ""; + } + logger.info("col: $col line: $line") + var start = col; + var end = col; + while( start > 0 && !line.get(start).isWhitespace()){ + start--; + } + while(end < line.length && !line.get(end).isWhitespace()){ + end++; + } + logger.info("start: $start end $end") + return line.substring(start+1, end); + } + + private fun isValidUrl(url: String): Boolean { + var matcher = pattern.matcher(url) + return matcher.matches() + } +}