From 71198d562e8b9f6f511d7fa092bc36e037ba84e9 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 11 Jan 2021 16:07:21 +0300 Subject: [PATCH] space: highlight current line when calling "Open on Space" from the editor GitOrigin-RevId: 911dcacf85c2ac47b3c66f283b6a0487e68b3c06 --- .../kotlin/com/intellij/space/utils/SpaceUrls.kt | 6 +++--- .../intellij/space/vcs/SpaceOpenInBrowserAction.kt | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/space/src/main/kotlin/com/intellij/space/utils/SpaceUrls.kt b/plugins/space/src/main/kotlin/com/intellij/space/utils/SpaceUrls.kt index dbdae4748ecf..971068842914 100644 --- a/plugins/space/src/main/kotlin/com/intellij/space/utils/SpaceUrls.kt +++ b/plugins/space/src/main/kotlin/com/intellij/space/utils/SpaceUrls.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.space.utils import circlet.client.api.* @@ -28,8 +28,8 @@ object SpaceUrls { fun issues(key: ProjectKey): String = p(key).issues().toUrl() - fun fileAnnotate(key: ProjectKey, repo: String, hash: String, relativePath: String): String = - p(key).fileAnnotate(repo, hash, relativePath).toUrl() + fun fileAnnotate(key: ProjectKey, repo: String, hash: String, relativePath: String, selectedLine: Int? = null): String = + p(key).fileAnnotate(repo, hash, relativePath, selectedLine).toUrl() // member fun member(profile: TD_MemberProfile): String = member(profile.username) diff --git a/plugins/space/src/main/kotlin/com/intellij/space/vcs/SpaceOpenInBrowserAction.kt b/plugins/space/src/main/kotlin/com/intellij/space/vcs/SpaceOpenInBrowserAction.kt index 9c429f013b85..02d523f0f195 100644 --- a/plugins/space/src/main/kotlin/com/intellij/space/vcs/SpaceOpenInBrowserAction.kt +++ b/plugins/space/src/main/kotlin/com/intellij/space/vcs/SpaceOpenInBrowserAction.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.space.vcs import circlet.client.api.ProjectKey @@ -145,8 +145,12 @@ class SpaceVcsOpenInBrowserActionGroup : val repoDescription = findProjectInfo(gitRepository, project) ?: return null - return repoDescription.projectInfos.map { OpenData.File(project, it, repoDescription.name, virtualFile, gitRepository) } + val editor = dataContext.getData(CommonDataKeys.EDITOR) + val line = if (editor != null && editor.document.lineCount >= 1) { + editor.caretModel.currentCaret.logicalPosition.line + } else null + return repoDescription.projectInfos.map { OpenData.File(project, it, repoDescription.name, virtualFile, line, gitRepository) } } private fun getDataFromHistory(dataContext: DataContext, project: Project): List? { @@ -221,13 +225,15 @@ class SpaceVcsOpenInBrowserActionGroup : class File(project: Project, projectKey: SpaceProjectInfo, repo: String, - private val virtualFile: VirtualFile, private val gitRepository: GitRepository) : OpenData(project, projectKey, repo) { + private val virtualFile: VirtualFile, + private val selectedLine: Int? = null, + private val gitRepository: GitRepository) : OpenData(project, projectKey, repo) { override val url: String? get() { val relativePath = VfsUtilCore.getRelativePath(virtualFile, gitRepository.root) ?: return null val hash = getCurrentFileRevisionHash(project, virtualFile) ?: return null - return SpaceUrls.fileAnnotate(info.key, repo, hash, relativePath) + return SpaceUrls.fileAnnotate(info.key, repo, hash, relativePath, selectedLine) } private fun getCurrentFileRevisionHash(project: Project, file: VirtualFile): String? {