Sublime Forum

Insert into a view

#1

I have 4 view in my sublime now. And I want to insert some text to one view. I am trying like this. but no luck.

getAllViews = self.window.views() jobView = getAllViews[1] jobEdit = jobView.begin_edit() jobView.insert(jobEdit, 0, 'Hello') jobView.end_edit(jobEdit)
Is there any better Idea to do this ?

Thanks

0 Likes

#2

What does it do? Have you tried turning on logging?

0 Likes

#3

jobEdit = jobView.begin_edit()
TypeError: begin_edit() missing 2 required positional arguments: ‘edit_token’ and ‘cmd’ this what I am getting. And I am trying do is when my pulgin run it will split the layout into 4 and I was to push some info to 4 layouts. Sublime split layout to 3 panel

Thanks

0 Likes

#4

Maybe I am doing it wrong. I am splitting my current view to 4. So I think I need something diff

0 Likes

#5

edit: Just remember that if you only want to insert text in the current cursor position of the active view (very unlikely), you can simply use:

view.run_command("insert", {"characters": "Hello"})

Look like you try your code in the console which is fine but doesn’t works for all cases, like when you need an edit token which is managed by ST itself.

You have to create a plugin to do the job:
Open the “Tools” menu and select “New Plugin…” to create a template for your plugin, in fact this template is exactly what you want to do.

Change the command name “ExampleCommand” to something more useful (MyTestInsertionCommand) and save the file to your user folder.
To run your command type in the console (note the name of the command):

view.run_command("my_test_insertion")

Now you can bind it to a keymap or add it to the Command Palette.

code.tutsplus.com/tutorials/how- … -net-22685

0 Likes

#6

Thanks for the reply and yes I am writing a new plugin and here is my code.

[code]import sublime
import sublime_plugin
import os, subprocess

class SpliterCommand(sublime_plugin.TextCommand):
def on_done(self, Regex):
self.window.set_layout({
“cols”: [0, 0.5, 1],
“rows”: [0.0, 0.33, 0.66, 1.0],
“cells”: [0, 0, 1, 3], [1, 0, 2, 1], [1, 1, 2, 2], [1, 2, 2, 3]]
})

def run(self, edit):
    self.editview = edit
            self.window = sublime.active_window()
    self.window.show_input_panel('User Input', "Hello",self.on_done,None,None)
    getAllViews = self.window.layouts()
    jobEdit = jobView.begin_edit()
    jobView.insert(edit, 0, 'Hello')
    jobView.end_edit(jobEdit)[/code]

Basically this will split the view to 4 layout and I want to insert some info to the 3 layouts in the right side. That’s what I am trying do :frowning:

0 Likes

#7

any hints :frowning:

0 Likes

#8

Just pinging for any updates :frowning:

0 Likes

#9

I think time to drop my hopes :frowning:

0 Likes

#10

Lots of people have inserted text into views. Have you tried googling or looking at other people’s code?

0 Likes

#11

The .begin_edit() and .end_edit() APIs have been deprecated in ST3 (actually, they have essentially been removed). You must do any modification in a sublime_plugin.TextCommand’s run method, which gets handed an edit parameter.

If you are within a WindowCommand, you must use view.run_command(...) to invoke a TextCommand that is allowed to modify a view’s content. The default “insert”, “insert_snippet” and “append” commands comes in hand here. (append doesn’t have any documentation yet since it’s fairly new)

0 Likes

#12

Thanks for the reply …

But I am splitting my current view to 4 layouts

def on_done(self, Regex): self.window.set_layout({ "cols": [0, 0.5, 1], "rows": [0.0, 0.33, 0.66, 1.0], "cells": [0, 0, 1, 3], [1, 0, 2, 1], [1, 1, 2, 2], [1, 2, 2, 3]] })

I want to put some char’s to my newly created layouts, that’s what I am trying to do :frowning:

0 Likes

#13

for view in self.window.views(): view.run_command("insert", {"characters": "this text\n"})

0 Likes

#14

But still that’s putting to the current view only and self.window.views() is not finding the layouts I think :frowning:

0 Likes

#15

self.window.set_layout({ "cols": [0, 0.5, 1], "rows": [0.0, 0.33, 0.66, 1.0], "cells": [0, 0, 1, 3], [1, 0, 2, 1], [1, 1, 2, 2], [1, 2, 2, 3]] })

After this do I need to do anything to make sure its get register or something ?

0 Likes

#16

got it stackoverflow gave me some answer :smile: stackoverflow.com/questions/3044 … i/30968354

0 Likes