Sublime Forum

Make a page with outlined links

#1

I want to make a page of search results in the same way that existing find-in-files does - with the clickable outlined matches.

Does anyone know if this (or anything similar) is possible please?

0 Likes

#2

It’s possible, but it’s very difficult because of the way the mouse handling works.

0 Likes

#3

SublimeTODO does this. As adzenith said, it’s difficult because of mouse handling works. Essentially, there are no context as there are with key commands. I suppose one possible way to do this is to set everything up to work and include a sample file, then let the user do it. Perhaps have create a mouse map entry with the following

    {
        "button": "button1", "count": 2,
        "command": "mouse_map",
        "press_command": "drag_select",
        "press_args": {"by": "words"}
    }
]

The user would then have to define a mouse_map command to take a particular action based on say…the view’s name. Not really sure the best way to go about this with what’s built in. But it could be a start.

0 Likes

#4

Cheers for that, the link will be especially useful. It doesn’t look like a lot of fun does it!!

I’m not sure what you mean by let the user do it though, could you elaborate please?

Am about to dive into this bit this afternoon so I’ll shout if (more likely when) I get stuck :smile:

An unrelated one: Is it possible to “read” the case sensitivity setting from the find panel? Say I wanted my plugin to search case sensitively if it’s set and not case sensitive if it’s unset. Can I pull that value from somewhere??

0 Likes

#5

Sure. So to play around, I defined a new plugin with the following…

[code]class MouseMapCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.settings().get(“todo_results”):
self.view.run_command(“mouse_goto_comment”)
if self.view.settings().get("_find_key_conflicts"):
line = self.view.substr(self.view.line(self.view.sel()[0]))
match = re.match(r"^\s+(.+?)\s+(.+?)\s+", line)
if match:
print(match.group(2))
resource_str = “Packages/%s/Default.sublime-keymap” % match.group(2)
package_str = “${packages}/%s/Default.sublime-keymap” % match.group(2)
try:
resource = sublime.load_resource(resource_str)
self.view.window.open_file(package_str)
except:

                package_str = "${packages}/%s/Default (%s).sublime-keymap" % (match.group(2), "Windows")
                self.view.window().open_file(package_str)[/code]

Note the first condition is checking for a “todo_results” setting. This is set on views created by SublimeTODO. Because SublimeTODO already has a command to jump to the results, I don’t have to do anything beyond that call that command. Plugins could, theoretically, do something similar. That is, define a command that will give the behavior desired, but require the end user to “activate it”. In this case, modifying their mousemap file and creating a custom command to be associated with it. Hope that makes things a little more clear.

I would think there would be a way, but I don’t know of it.

0 Likes