Esempio n. 1
0
def _is_insert_mode(view, operator, operand, match_all):
    return _check_query_context_value(
        (not view.settings().get('command_mode') and is_view(view)),
        operator,
        operand,
        match_all
    )
Esempio n. 2
0
def init_state(view):
    # type: (...) -> None
    # Initialise view state.
    #
    # Runs at startup and every time a view gets activated, loaded, etc.
    #
    # Args:
    #   :view (sublime.View):

    if not is_view(view):
        # Abort if we got a console, widget, panel...
        try:
            # XXX: All this seems to be necessary here.
            if not is_ignored_but_command_mode(view):
                view.settings().set('command_mode', False)
                view.settings().set('inverse_caret_state', False)

            view.settings().erase('vintage')
        except Exception:
            # TODO [review] Exception handling
            _log.debug(
                'error initialising irregular view i.e. console, widget, panel, etc.'
            )
        finally:
            return

    state = State(view)

    if not state.reset_during_init:
        # Probably exiting from an input panel, like when using '/'. Don't
        # reset the global state, as it may contain data needed to complete
        # the command that's being built.
        state.reset_during_init = True
        return

    # Non-standard user setting.
    reset = state.settings.view['vintageous_reset_mode_when_switching_tabs']
    # XXX: If the view was already in normal mode, we still need to run the
    # init code. I believe this is due to Sublime Text (intentionally) not
    # serializing the inverted caret state and the command_mode setting when
    # first loading a file.
    # If the mode is unknown, it might be a new file. Let normal mode setup
    # continue.
    if not reset and (state.mode not in (NORMAL, UNKNOWN)):
        return

    # If we have no selections, add one.
    if len(state.view.sel()) == 0:
        _log.debug('no selection, adding one at 0...')
        state.view.sel().add(Region(0))

    if state.mode in (VISUAL, VISUAL_LINE):
        # TODO: Don't we need to pass a mode here?
        view.window().run_command('_enter_normal_mode', {'from_init': True})

    elif state.mode in (INSERT, REPLACE):
        # TODO: Don't we need to pass a mode here?
        view.window().run_command('_enter_normal_mode', {'from_init': True})

    elif (view.has_non_empty_selection_region() and state.mode != VISUAL):
        # Runs, for example, when we've performed a search via ST3 search panel
        # and we've pressed 'Find All'. In this case, we want to ensure a
        # consistent state for multiple selections.
        # TODO We could end up with multiple selections in other ways that bypass init_state.
        state.mode = VISUAL
    else:
        # This may be run when we're coming from cmdline mode.
        pseudo_visual = view.has_non_empty_selection_region()
        mode = VISUAL if pseudo_visual else state.mode
        # TODO: Maybe the above should be handled by State?
        state.enter_normal_mode()
        view.window().run_command('_enter_normal_mode', {
            'mode': mode,
            'from_init': True
        })

    state.reset_command_data()
Esempio n. 3
0
    def vi_insert_mode_aware(self, key, operator, operand, match_all):
        _is_command_mode = self.view.settings().get('command_mode')
        _is_view = is_view(self.view)

        return self._check((not _is_command_mode and _is_view), operator,
                           operand, match_all)