From dae576090064fc882767eeeca38f06a7ac42c86f Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 23 Aug 2020 12:52:03 +0100 Subject: [PATCH] Ensure signs are only padded when 1 display cell --- python3/vimspector/breakpoints.py | 12 +++++++++--- python3/vimspector/code.py | 4 +++- python3/vimspector/utils.py | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index 59d1370..917804b 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -53,13 +53,19 @@ class ProjectBreakpoints( object ): self._next_sign_id = 1 if not utils.SignDefined( 'vimspectorBP' ): - vim.command( 'sign define vimspectorBP text=\\ ● texthl=WarningMsg' ) + utils.DefineSign( 'vimspectorBP', + text = '●', + texthl = 'WarningMsg' ) if not utils.SignDefined( 'vimspectorBPCond' ): - vim.command( 'sign define vimspectorBPCond text=\\ ◆ texthl=WarningMsg' ) + utils.DefineSign( 'vimspectorBPCond', + text = '◆', + texthl = 'WarningMsg' ) if not utils.SignDefined( 'vimspectorBPDisabled' ): - vim.command( 'sign define vimspectorBPDisabled text=\\ ● texthl=LineNr' ) + utils.DefineSign( 'vimspectorBPDisabled', + text = '●', + texthl = 'LineNr' ) def ConnectionUp( self, connection ): diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 8e33ece..d8bd208 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -51,7 +51,9 @@ class CodeView( object ): vim.command( 'nnoremenu WinBar.✕ :call vimspector#Reset()' ) if not utils.SignDefined( 'vimspectorPC' ): - vim.command( 'sign define vimspectorPC text=\\ ▶ texthl=MatchParen' ) + utils.DefineSign( 'vimspectorPC', + text = '▶', + texthl = 'MatchParen' ) def SetCurrentFrame( self, frame ): diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index bc7c168..af76150 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -777,3 +777,13 @@ def WindowID( window, tab=None ): if tab is None: tab = window.tabpage return int( Call( 'win_getid', window.number, tab.number ) ) + + +def DefineSign( name, text, texthl, col = 'right' ): + if col == 'right': + if int( Call( 'strdisplaywidth', text ) ) < 2: + text = ' ' + text + + text = text.replace( ' ', r'\ ' ) + + vim.command( f'sign define { name } text={ text } texthl={ texthl }' )