pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

Broken selection replace #1125

Closed moteus closed 2 years ago

moteus commented 2 years ago

Trying this code from the local console

e = ide:GetEditor(); e:SetText('-- local str = [[ `voo` ]]\r\n'); e:Refresh(); e:Update(); e:SetSelection(0,28); e:ReplaceSelection('local str = [[ `voo` ]]\r\n');

I've got

-- local str = [[ `voo` ]]
local str = [[ `voo` ]]

Note that without Refresh/Update I got

local str = [[ `voo` ]]

So I belive its something related with comment styles.

PS. I solve this with DeleteRange / InsertText

e = ide:GetEditor(); e:SetText('-- local str = [[ `voo` ]]\r\n'); e:Refresh(); e:Update(); e:DeleteRange(0,28); e:InsertText(0, 'local str = [[ `voo` ]]\r\n');
pkulchenko commented 2 years ago

@moteus, it's not "broken", it's a side-effect of the markdown markup in comments, which hides some of the characters, and hidden characters are not removed by Cut and ReplaceSelection calls. DeleteRange does ignore those, so that's why it works.

ReplaceTarget should work as well, so you may want to use that (although you'll have to use SetTargetStart and SetTargetEnd to mark the target). Also see #827.