Clean up codebase and improve file loading
- Moved plugins to proper sub groups (autopairs, code_minimap, colorize, commentzar, info_bar, markdown_preview, prettify_json, search_replace, tabs_bar, telescope, toggle_source_view, lsp_client) - Add filter_out_loaded_files to prevent opening already-loaded files - Add INDEPENDENT source view state - Fix cursor scroll position on buffer switch - Fix signal blocking during file load - Fix word boundary in completion provider - Refactor code events into single events module
This commit is contained in:
70
plugins/code/ui/markdown_preview/plugin.py
Normal file
70
plugins/code/ui/markdown_preview/plugin.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
from plugins.plugin_types import PluginCode
|
||||
|
||||
from .markdown_preview import MarkdownPreview
|
||||
|
||||
|
||||
|
||||
markdown_preview = MarkdownPreview()
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _set_file(self, buffer):
|
||||
event = Event_Factory.create_event(
|
||||
"get_file", buffer = buffer
|
||||
)
|
||||
self.emit_to("files", event)
|
||||
|
||||
if not event.response or not event.response.get_location(): return
|
||||
|
||||
markdown_preview.fpath = event.response.get_location().get_path()
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
if isinstance(event, Code_Event_Types.FocusedViewEvent):
|
||||
self._set_file(event.view.get_buffer())
|
||||
markdown_preview._do_markdown_translate(event.view.get_buffer())
|
||||
elif isinstance(event, Code_Event_Types.TextChangedEvent):
|
||||
self._set_file(event.buffer)
|
||||
markdown_preview._do_markdown_translate(event.buffer)
|
||||
|
||||
def load(self):
|
||||
separator_right = self.request_ui_element("separator-right")
|
||||
markdown_preview.set_relative_to(separator_right)
|
||||
|
||||
event = Event_Factory.create_event("register_command",
|
||||
command_name = "tggle_markdown_preview",
|
||||
command = Handler,
|
||||
binding_mode = "released",
|
||||
binding = "<Shift><Control>m"
|
||||
)
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
def run(self):
|
||||
...
|
||||
|
||||
|
||||
class Handler:
|
||||
@staticmethod
|
||||
def execute(
|
||||
view: any,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Markdown Preview")
|
||||
|
||||
if not markdown_preview.can_hide:
|
||||
markdown_preview.can_hide = True
|
||||
|
||||
markdown_preview.popdown() if markdown_preview.is_visible() else markdown_preview.popup()
|
||||
Reference in New Issue
Block a user