summaryrefslogtreecommitdiff
path: root/logcat
diff options
context:
space:
mode:
authorAlon Albert <aalbert@google.com>2022-08-01 08:20:15 -0700
committerAlon Albert <aalbert@google.com>2022-08-01 16:42:47 +0000
commit745586b48228b0ee9770f4c2e7b9830778f9fadf (patch)
treee6cbeb458fed5ae076fb0014127cce77bd81995e /logcat
parent8f28929041ea8851e969232fa21567ddc8ce3373 (diff)
downloadidea-745586b48228b0ee9770f4c2e7b9830778f9fadf.tar.gz
Make ScrollToTheEndToolbarAction Action Consider Scrollbar Pos
Bug: 239095674 Test: n/a Change-Id: I66b7048de650df98074ad76544b8ee37b767303c
Diffstat (limited to 'logcat')
-rw-r--r--logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt7
-rw-r--r--logcat/src/com/android/tools/idea/logcat/actions/LogcatScrollToTheEndToolbarAction.kt38
2 files changed, 40 insertions, 5 deletions
diff --git a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
index 35deaae85bc..d547f969e33 100644
--- a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
+++ b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
@@ -38,6 +38,7 @@ import com.android.tools.idea.logcat.actions.ClearLogcatAction
import com.android.tools.idea.logcat.actions.CreateScratchFileAction
import com.android.tools.idea.logcat.actions.LogcatFoldLinesLikeThisAction
import com.android.tools.idea.logcat.actions.LogcatFormatAction
+import com.android.tools.idea.logcat.actions.LogcatScrollToTheEndToolbarAction
import com.android.tools.idea.logcat.actions.LogcatSplitterActions
import com.android.tools.idea.logcat.actions.LogcatToggleUseSoftWrapsToolbarAction
import com.android.tools.idea.logcat.actions.NextOccurrenceToolbarAction
@@ -103,7 +104,6 @@ import com.intellij.openapi.actionSystem.Separator
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.RangeMarker
-import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction
import com.intellij.openapi.editor.event.CaretEvent
import com.intellij.openapi.editor.event.CaretListener
import com.intellij.openapi.editor.event.EditorMouseEvent
@@ -465,10 +465,7 @@ internal class LogcatMainPanel(
add(ClearLogcatAction(this@LogcatMainPanel))
add(PauseLogcatAction(this@LogcatMainPanel))
add(RestartLogcatAction(this@LogcatMainPanel))
- add(ScrollToTheEndToolbarAction(editor).apply {
- @Suppress("DialogTitleCapitalization")
- templatePresentation.text = LogcatBundle.message("logcat.scroll.to.end.action.text")
- })
+ add(LogcatScrollToTheEndToolbarAction(editor))
add(PreviousOccurrenceToolbarAction(LogcatOccurrenceNavigator(project, editor)))
add(NextOccurrenceToolbarAction(LogcatOccurrenceNavigator(project, editor)))
add(LogcatToggleUseSoftWrapsToolbarAction(editor))
diff --git a/logcat/src/com/android/tools/idea/logcat/actions/LogcatScrollToTheEndToolbarAction.kt b/logcat/src/com/android/tools/idea/logcat/actions/LogcatScrollToTheEndToolbarAction.kt
new file mode 100644
index 00000000000..8e29871267c
--- /dev/null
+++ b/logcat/src/com/android/tools/idea/logcat/actions/LogcatScrollToTheEndToolbarAction.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tools.idea.logcat.actions
+
+import com.android.tools.idea.logcat.LogcatBundle
+import com.android.tools.idea.logcat.util.isScrollAtBottom
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction
+import com.intellij.openapi.editor.ex.EditorEx
+
+/**
+ * A Logcat specific version of [ScrollToTheEndToolbarAction]
+ *
+ * This version takes into account the scrollbar position for toggling the action state.
+ */
+internal class LogcatScrollToTheEndToolbarAction(private val editor: EditorEx): ScrollToTheEndToolbarAction(editor) {
+ init {
+ @Suppress("DialogTitleCapitalization")
+ templatePresentation.text = LogcatBundle.message("logcat.scroll.to.end.action.text")
+ }
+
+ override fun isSelected(e: AnActionEvent): Boolean {
+ return super.isSelected(e) && editor.isScrollAtBottom(false)
+ }
+} \ No newline at end of file