Sublime Forum

Left-justify the view

#1

I’m trying to create a command to pan the display left all way, i.e., to show the left edge of the page.

I tried this:

def left_adjust(view):
    copy, regions = copy_regions(view)
    move_to_hard_bol(view)
    regions.clear()
    regions.add_all(copy)

Where copy_regions, move_to_hard_bol are defined as follows:

def copy_regions(view):
    regions = view.sel()
    copy = []
    for r in regions:
        copy.append(sublime.Region(r.a, r.b))
    return copy, regions

def move_to_hard_bol(view, extend=False):
    copy, regions = copy_regions(view)
    regions.clear()
    to_be_added = []
    for i in range(len(copy)):
        line = view.line(copy[i].b)
        if extend:
            z = sublime.Region(copy[i].a, line.begin())
        else:
            z = sublime.Region(line.begin(), line.begin())
        to_be_added.append(z)
    regions.add_all(to_be_added)

This used to work for me, somehow it’s not working anymore.

Any ideas for how to left-justify the view, while leaving the caret in-place?

0 Likes

#2

Does something like this work for you?

import sublime
import sublime_plugin


class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        viewport = self.view.viewport_position()
        self.view.set_viewport_position((0, viewport[1]))

It grabs the current viewport position and then resets it with a 0 X position.

0 Likes

#3

Yes it works! Thanks.

0 Likes