Clone view plugin for ZeroBrane Studio

I received several questions about whether it's possible to add ability to see the same file in different editor tabs in ZeroBrane Studio and thought it would be a good test for the current plugin interface.

The Scintilla editor component that is used in ZeroBrane Studio includes a nice feature that allows two editors to share the same document, with changes made in one editor being immediately seen in the other one. The code is very simple ('e1' is the editor you are cloning and 'e2' is the new editor):

 local docpointer = e1:GetDocPointer()

I wrapped this code in a plugin that allows users to clone an editor tab vertically or horizontally. Save this plugin as cloneview.lua to packages/ folder, restart ZeroBrane Studio, and right click on one of editor tabs to select 'Clone Vertically' and 'Clone Horizontally'.

return {
  name = "Clone view plugin",
  description = "Clones the current editor tab.",
  author = "Paul Kulchenko",
  version = 0.11,

  onMenuEditorTab = function(self, menu, notebook, event, index)
    local idvert = ID(self.fname..".clone.vert")
    local idhorz = ID(self.fname..".clone.horz")

    local cloner = function(event)
      local e1 = ide:GetEditor(index)
      local e2 = NewFile("clone: "..ide:GetDocument(e1):GetFileName())
      local docpointer = e1:GetDocPointer()
        event:GetId() == idhorz and wx.wxRIGHT or wx.wxBOTTOM)

    menu:Append(idhorz, "Clone Horizontally")
    menu:Append(idvert, "Clone Vertically")
    notebook:Connect(idvert, wx.wxEVT_COMMAND_MENU_SELECTED, cloner)
    notebook:Connect(idhorz, wx.wxEVT_COMMAND_MENU_SELECTED, cloner)

[Updated on 09/21/2013] The plugin code has been updated to use index parameter that refers to a correct index in split notebook situations. This functionality requires using v0.39 of ZeroBrane Studio (when released) or the current master.

You should get a copy of my slick ZeroBrane Studio IDE.

Leave a comment

what will you say?