aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/App.xaml
blob: 0b87025f5efd97e23826a297173e1048652fd98a (plain)
1
2
3
4
5
6
7
8
9
<Application x:Class="Tango.MachineStudio.Publisher.UI.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Tango.MachineStudio.Publisher.UI"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>
t .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
--
-- 50-smooth_scroll.lua
--
-- * Animates a half-page scroll by stepping <C-e>/<C-y> (plus j/k) over a short timer.
--
-- User commands:
--   `ScrollSmoothDown`: scroll down smoothly
--   `ScrollSmoothUp`: scroll up smoothly
--

local Dir = {
	UP = 1,
	DOWN = 2,
}

local function smooth_scroll(dir)
	local scroll_at_boundary, cursor_at_boundary
	if dir == Dir.DOWN then
		scroll_at_boundary = function()
			return vim.fn.line("w$") == vim.api.nvim_buf_line_count(0)
		end
		cursor_at_boundary = function()
			return vim.fn.line(".") == vim.api.nvim_buf_line_count(0)
		end
	else
		scroll_at_boundary = function()
			return vim.fn.line("w0") == 1
		end
		cursor_at_boundary = function()
			return vim.fn.line(".") == 1
		end
	end
	-- bail only when the cursor itself can't move further; at the viewport boundary <C-e>/<C-y>
	-- no-op but we still want j/k to walk the cursor
	if cursor_at_boundary() then
		return
	end
	local win_height = vim.api.nvim_win_get_height(0)
	local duration, sleep_duration = 100, 16 -- 60 fps
	local distance = math.floor(win_height / 2)
	-- We want a movement every `sleep_duration` msec
	local steps_number = math.ceil(duration / sleep_duration)
	local step = distance / steps_number
	local scroll_keys = dir == Dir.DOWN and "\\<C-e>j" or "\\<C-y>k"
	local cursor_keys = dir == Dir.DOWN and "j" or "k"
	local prev = 0
	for i = 1, steps_number do
		local cur = math.ceil(step * i)
		local delta = cur - prev
		prev = cur
		vim.defer_fn(function()
			for _ = 1, delta do
				if cursor_at_boundary() then
					return
				end
				-- past the viewport boundary <C-e>/<C-y> no-op; just walk the cursor
				local keys = scroll_at_boundary() and cursor_keys or scroll_keys
				vim.cmd('exec "normal! ' .. keys .. '"')
			end
		end, sleep_duration * i)
	end
end

local function smooth_scroll_up()
	smooth_scroll(Dir.UP)
end

local function smooth_scroll_down()
	smooth_scroll(Dir.DOWN)
end

----------------------------------------------------------------------------------------------------

vim.api.nvim_create_user_command(
	"ScrollSmoothDown",
	smooth_scroll_down,
	{ desc = "Scroll down smoothly" }
)
vim.api.nvim_create_user_command(
	"ScrollSmoothUp",
	smooth_scroll_up,
	{ desc = "Scroll up smoothly" }
)