Click to open URL in Markdown file? #418
-
When editing a Markdown file, URLs are underlined (as expected), which suggests that they are recognized by the lexer. Therefore it should be possible to write a keybinding so that the user can Shift+click on a URL to open it in their default web browser. I'm new to Textadept and Lua, and not sure how to approach this. Would anyone be able to share a code snippet that would detect if the user has clicked on a particular Lexer element or, if this is too difficult, detect if the cursor is within a particular element? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
A quick glance at the docs revealed only a double click event but it might be a start. events.connect(events.DOUBLE_CLICK, function(modifiers)
if not (modifiers & view.MOD_SHIFT) then return end
if buffer:get_lexer(true) ~= 'markdown' then return end
textadept.editing.select_enclosed('(', ')')
link = buffer:get_sel_text()
if _G.WIN32 then
os.spawn('start ' .. link)
else
os.spawn('open ' .. link)
end
end) |
Beta Was this translation helpful? Give feedback.
-
If you want a text region to respond to a click, you have to use an indicator. Since lexer elements are not marked with indicators, you'd have to write a function to search for regions to mark, mark them, and then write an
Alternatively, you can write a routine to check if the caret is under a link, extract that link, and open it in your browser:
I haven't tested either of these code snippets, but that's the idea. |
Beta Was this translation helpful? Give feedback.
If you want a text region to respond to a click, you have to use an indicator. Since lexer elements are not marked with indicators, you'd have to write a function to search for regions to mark, mark them, and then write an
events.INDICATOR_CLICK
handler to respond. The following example is from an old quick reference book. It's not exactly what you need, but it illustrates the process: