From 20cd0e16d2b37586e4946e066cc5b604d3ec4035 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Tue, 15 Nov 2022 17:12:47 -0400 Subject: settings: apply force_scrollbar_status on the fly Also added additional flag to support applying the status bar force state globally and not only to document views. --- plugins/settings.lua | 63 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/plugins/settings.lua b/plugins/settings.lua index 9c7cd31..89796b1 100644 --- a/plugins/settings.lua +++ b/plugins/settings.lua @@ -5,6 +5,7 @@ local common = require "core.common" local command = require "core.command" local keymap = require "core.keymap" local style = require "core.style" +local DocView = require "core.docview" -- check if widget is installed before proceeding local widget_found, Widget = pcall(require, "widget") @@ -394,6 +395,56 @@ settings.add("User Interface", return value * SCALE end }, + { + label = "Force Scrollbar Status", + description = "Choose a fixed scrollbar state instead of resizing it on mouse hover.", + path = "force_scrollbar_status", + type = settings.type.SELECTION, + default = false, + values = { + {"Disabled", false}, + {"Expanded", "expanded"}, + {"Contracted", "contracted"} + }, + on_apply = function(value) + local mode = config.force_scrollbar_status_mode or "global" + local globally = mode == "global" + local views = core.root_view.root_node:get_children() + for _, view in ipairs(views) do + if globally or view:extends(DocView) then + view.h_scrollbar:set_forced_status(value) + view.v_scrollbar:set_forced_status(value) + else + view.h_scrollbar:set_forced_status(false) + view.v_scrollbar:set_forced_status(false) + end + end + end + }, + { + label = "Force Scrollbar Status Mode", + description = "Choose between applying globally or document views only.", + path = "force_scrollbar_status_mode", + type = settings.type.SELECTION, + default = "global", + values = { + {"Documents", "docview"}, + {"Globally", "global"} + }, + on_apply = function(value) + local globally = value == "global" + local views = core.root_view.root_node:get_children() + for _, view in ipairs(views) do + if globally or view:extends(DocView) then + view.h_scrollbar:set_forced_status(config.force_scrollbar_status) + view.v_scrollbar:set_forced_status(config.force_scrollbar_status) + else + view.h_scrollbar:set_forced_status(false) + view.v_scrollbar:set_forced_status(false) + end + end + end + }, { label = "Disable Cursor Blinking", description = "Disables cursor blinking on text input elements.", @@ -542,18 +593,6 @@ settings.add("Editor", path = "scroll_past_end", type = settings.type.TOGGLE, default = true - }, - { - label = "Force Scrollbar Status", - description = "Choose an fixed scrollbar state instead of resizing it on mouse hover.", - path = "force_scrollbar_status", - type = settings.type.SELECTION, - default = false, - values = { - {"Disabled", false}, - {"Expanded", "expanded"}, - {"Contracted", "contracted"} - } } } ) -- cgit v1.2.3