add a __tostring method to every object (#1534)
* added a stupid __tostring to every object * moved every __tostring to just after the :extend() call --------- Co-authored-by: Adam <adamdharrison@gmail.com> (cherry picked from commit 880e7f1fa1521cdf176f44627a27c901e187058e)
This commit is contained in:
@@ -10,6 +10,8 @@ local View = require "core.view"
|
||||
---@field super core.doc
|
||||
local SingleLineDoc = Doc:extend()
|
||||
|
||||
function SingleLineDoc:__tostring() return "SingleLineDoc" end
|
||||
|
||||
function SingleLineDoc:insert(line, col, text)
|
||||
SingleLineDoc.super.insert(self, line, col, text:gsub("\n", ""))
|
||||
end
|
||||
@@ -18,6 +20,8 @@ end
|
||||
---@field super core.docview
|
||||
local CommandView = DocView:extend()
|
||||
|
||||
function CommandView:__tostring() return "CommandView" end
|
||||
|
||||
CommandView.context = "application"
|
||||
|
||||
local max_suggestions = 10
|
||||
@@ -391,5 +395,4 @@ function CommandView:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return CommandView
|
||||
|
||||
@@ -33,6 +33,8 @@ local DIVIDER = {}
|
||||
---@field current_scale number
|
||||
local ContextMenu = Object:extend()
|
||||
|
||||
function ContextMenu:__tostring() return "ContextMenu" end
|
||||
|
||||
---A unique value representing the divider in a context menu.
|
||||
ContextMenu.DIVIDER = DIVIDER
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ local Object = require "core.object"
|
||||
|
||||
local Highlighter = Object:extend()
|
||||
|
||||
function Highlighter:__tostring() return "Highlighter" end
|
||||
|
||||
function Highlighter:new(doc)
|
||||
self.doc = doc
|
||||
@@ -126,5 +127,4 @@ function Highlighter:each_token(idx)
|
||||
return tokenizer.each_token(self:get_line(idx).tokens)
|
||||
end
|
||||
|
||||
|
||||
return Highlighter
|
||||
|
||||
@@ -8,6 +8,7 @@ local common = require "core.common"
|
||||
---@class core.doc : core.object
|
||||
local Doc = Object:extend()
|
||||
|
||||
function Doc:__tostring() return "Doc" end
|
||||
|
||||
local function split_lines(text)
|
||||
local res = {}
|
||||
|
||||
@@ -11,6 +11,8 @@ local View = require "core.view"
|
||||
---@field super core.view
|
||||
local DocView = View:extend()
|
||||
|
||||
function DocView:__tostring() return "DocView" end
|
||||
|
||||
DocView.context = "session"
|
||||
|
||||
local function move_to_line_offset(dv, line, col, offset)
|
||||
@@ -591,5 +593,4 @@ function DocView:draw()
|
||||
self:draw_scrollbar()
|
||||
end
|
||||
|
||||
|
||||
return DocView
|
||||
|
||||
@@ -6,6 +6,8 @@ local View = require "core.view"
|
||||
---@field super core.view
|
||||
local EmptyView = View:extend()
|
||||
|
||||
function EmptyView:__tostring() return "EmptyView" end
|
||||
|
||||
function EmptyView:get_name()
|
||||
return "Get Started"
|
||||
end
|
||||
|
||||
@@ -33,9 +33,10 @@ local function get_item_height(item)
|
||||
return h
|
||||
end
|
||||
|
||||
|
||||
local LogView = View:extend()
|
||||
|
||||
function LogView:__tostring() return "LogView" end
|
||||
|
||||
LogView.context = "session"
|
||||
|
||||
|
||||
@@ -222,5 +223,4 @@ function LogView:draw()
|
||||
LogView.super.draw_scrollbar(self)
|
||||
end
|
||||
|
||||
|
||||
return LogView
|
||||
|
||||
@@ -15,6 +15,8 @@ local noop = function() end
|
||||
---@field super core.view
|
||||
local NagView = View:extend()
|
||||
|
||||
function NagView:__tostring() return "NagView" end
|
||||
|
||||
function NagView:new()
|
||||
NagView.super.new(self)
|
||||
self.size.y = 0
|
||||
|
||||
@@ -9,6 +9,8 @@ local View = require "core.view"
|
||||
---@class core.node : core.object
|
||||
local Node = Object:extend()
|
||||
|
||||
function Node:__tostring() return "Node" end
|
||||
|
||||
function Node:new(type)
|
||||
self.type = type or "leaf"
|
||||
self.position = { x = 0, y = 0 }
|
||||
|
||||
@@ -11,6 +11,8 @@ local DocView = require "core.docview"
|
||||
---@field mouse core.view.position
|
||||
local RootView = View:extend()
|
||||
|
||||
function RootView:__tostring() return "RootView" end
|
||||
|
||||
function RootView:new()
|
||||
RootView.super.new(self)
|
||||
self.root_node = Node()
|
||||
@@ -494,5 +496,4 @@ function RootView:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return RootView
|
||||
|
||||
@@ -19,6 +19,8 @@ local Object = require "core.object"
|
||||
---@class core.scrollbar : core.object
|
||||
local Scrollbar = Object:extend()
|
||||
|
||||
function Scrollbar:__tostring() return "Scrollbar" end
|
||||
|
||||
---@class ScrollbarOptions
|
||||
---@field direction "v" | "h" @Vertical or Horizontal
|
||||
---@field alignment "s" | "e" @Start or End (left to right, top to bottom)
|
||||
@@ -339,5 +341,4 @@ function Scrollbar:draw()
|
||||
self:draw_thumb()
|
||||
end
|
||||
|
||||
|
||||
return Scrollbar
|
||||
|
||||
@@ -34,6 +34,8 @@ local Object = require "core.object"
|
||||
---@field hide_messages boolean
|
||||
local StatusView = View:extend()
|
||||
|
||||
function StatusView:__tostring() return "StatusView" end
|
||||
|
||||
---Space separator
|
||||
---@type string
|
||||
StatusView.separator = " "
|
||||
@@ -72,6 +74,8 @@ StatusView.separator2 = " | "
|
||||
---@field cached_item core.statusview.styledtext
|
||||
local StatusViewItem = Object:extend()
|
||||
|
||||
function StatusViewItem:__tostring() return "StatusViewItem" end
|
||||
|
||||
---Available StatusViewItem options.
|
||||
---@class core.statusview.item.options : table
|
||||
---A condition to evaluate if the item should be displayed. If a string
|
||||
|
||||
@@ -29,6 +29,8 @@ local title_commands = {
|
||||
---@field super core.view
|
||||
local TitleView = View:extend()
|
||||
|
||||
function TitleView:__tostring() return "TitleView" end
|
||||
|
||||
local function title_view_height()
|
||||
return style.font:get_height() + style.padding.y * 2
|
||||
end
|
||||
|
||||
+2
-1
@@ -48,6 +48,8 @@ local Scrollbar = require "core.scrollbar"
|
||||
---@field current_scale number
|
||||
local View = Object:extend()
|
||||
|
||||
function View:__tostring() return "View" end
|
||||
|
||||
-- context can be "application" or "session". The instance of objects
|
||||
-- with context "session" will be closed when a project session is
|
||||
-- terminated. The context "application" is for functional UI elements.
|
||||
@@ -307,5 +309,4 @@ end
|
||||
function View:draw()
|
||||
end
|
||||
|
||||
|
||||
return View
|
||||
|
||||
@@ -9,6 +9,8 @@ local View = require "core.view"
|
||||
---@class plugins.projectsearch.resultsview : core.view
|
||||
local ResultsView = View:extend()
|
||||
|
||||
function ResultsView:__tostring() return "ResultsView" end
|
||||
|
||||
ResultsView.context = "session"
|
||||
|
||||
function ResultsView:new(path, text, fn)
|
||||
@@ -237,7 +239,6 @@ function ResultsView:draw()
|
||||
self:draw_scrollbar()
|
||||
end
|
||||
|
||||
|
||||
---@param path string
|
||||
---@param text string
|
||||
---@param fn fun(line_text:string):...
|
||||
|
||||
@@ -8,6 +8,7 @@ local View = require "core.view"
|
||||
|
||||
local ToolbarView = View:extend()
|
||||
|
||||
function ToolbarView:__tostring() return "ToolbarView" end
|
||||
|
||||
function ToolbarView:new()
|
||||
ToolbarView.super.new(self)
|
||||
|
||||
@@ -38,6 +38,8 @@ end
|
||||
|
||||
local TreeView = View:extend()
|
||||
|
||||
function TreeView:__tostring() return "TreeView" end
|
||||
|
||||
function TreeView:new()
|
||||
TreeView.super.new(self)
|
||||
self.scrollable = true
|
||||
|
||||
Reference in New Issue
Block a user