mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 20:14:54 +02:00
Start working on multi-line selection for console
Unfortunately UITextEdit is really bad in terms of performance. It cannot be used as overlying widget (just like in terminal). On the other hand we could optimize it by rewriting (unfortunately) the whole widget. There still is a lot of things to do, but for now it is possible to select several lines of text and copy it using CTRL + C. In order to make text copyable in context menu it will be required to override onMousePress (return true).
This commit is contained in:
@@ -117,9 +117,15 @@ function init()
|
||||
if not consoleBuffer then return false end
|
||||
|
||||
local consoleLabel = consoleBuffer:getFocusedChild()
|
||||
if not consoleLabel or not consoleLabel:hasSelection() then return false end
|
||||
if not consoleLabel.selectionChildFirst or not consoleLabel.selectionChildLast then return false end
|
||||
|
||||
g_window.setClipboardText(consoleLabel:getSelection())
|
||||
local text = {}
|
||||
for selectionChild = consoleLabel.selectionChildFirst, consoleLabel.selectionChildLast do
|
||||
local label = consoleLabel:getParent():getChildByIndex(selectionChild)
|
||||
table.insert(text, label:getSelection())
|
||||
end
|
||||
|
||||
g_window.setClipboardText(table.concat(text, '\r\n'))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -576,10 +582,62 @@ function addTabText(text, speaktype, tab, creatureName)
|
||||
end
|
||||
end
|
||||
|
||||
-- remove selection
|
||||
local removeSelectedText = function(self)
|
||||
local parent = self:getParent()
|
||||
if self.selectionChildFirst and self.selectionChildLast then
|
||||
for selectionChild = self.selectionChildFirst, self.selectionChildLast do
|
||||
local label = parent:getChildByIndex(selectionChild)
|
||||
if label ~= self then
|
||||
label:clearSelection()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
label.name = creatureName
|
||||
label.onMouseRelease = function (self, mousePos, mouseButton)
|
||||
label.onMouseRelease = function(self, mousePos, mouseButton)
|
||||
-- TODO: regain lost selection
|
||||
processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab)
|
||||
end
|
||||
label.onFocusChange = function(self, focused, reason)
|
||||
-- TODO: we are losing focus on context menu and therefore the selection
|
||||
if not focused then removeSelectedText(self) end
|
||||
end
|
||||
label.onMousePress = function(self, mousePos, button)
|
||||
if button == MouseLeftButton then removeSelectedText(self) end
|
||||
end
|
||||
label.onMouseMove = function(self, mousePos, mouseMoved)
|
||||
if self:isPressed() then
|
||||
local parent = self:getParent()
|
||||
local selfIndex = parent:getChildIndex(self)
|
||||
local child = parent:getChildByPos(mousePos)
|
||||
local childIndex = parent:getChildIndex(child)
|
||||
|
||||
-- remove old selection
|
||||
removeSelectedText(self)
|
||||
|
||||
-- choose new selection
|
||||
if child and child ~= self then
|
||||
self.selectionChildFirst = math.min(selfIndex, childIndex)
|
||||
self.selectionChildLast = math.max(selfIndex, childIndex)
|
||||
|
||||
for selectionChild = self.selectionChildFirst + 1, self.selectionChildLast - 1 do
|
||||
local label = parent:getChildByIndex(selectionChild)
|
||||
label:selectAll()
|
||||
end
|
||||
|
||||
local textPos = child:getTextPos(mousePos)
|
||||
if childIndex > selfIndex then
|
||||
child:setSelection(0, textPos)
|
||||
else
|
||||
child:setSelection(string.len(child:getText()), textPos)
|
||||
end
|
||||
elseif not child then
|
||||
-- TODO: out of bonding rect selection
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if consoleBuffer:getChildCount() > MAX_LINES then
|
||||
consoleBuffer:getFirstChild():destroy()
|
||||
|
Reference in New Issue
Block a user