summaryrefslogtreecommitdiff
path: root/note_tools/today.py
blob: 9afad5d62c381d1c4f76dd3d208bea05a25c0c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from . import NoteBaseCommand
import os
import sublime
import sublime_plugin
from pathlib import Path 
from typing import Optional

class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand):
    def run(self):
        project_data = self.window.project_data()

        def open_file(success: bool, message: str, file_path: Optional[str]):
            if success:
                new_view = self.window.open_file(file_path)
                self.set_cursor_position(new_view)
            else:
                sublime.message_dialog(message)

        self.create_note(project_data=project_data, callback=open_file)

    def set_cursor_position(self, view):
        # Set the cursor position two lines beneath the underline
        def on_load():
            view.run_command("move_to", {"to": "bof"})
            for _ in range(3):
                view.run_command("move", {"by": "lines", "forward": True})
        
        # Add an event listener for when the file is loaded
        if view.is_loading():
            sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100)
        else:
            on_load()