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).
master
Konrad Kuśnierz 9 years ago
parent 34e2fa1d49
commit f35c939fc3

@ -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()

@ -796,7 +796,6 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
}
return true;
}
return false;
}
@ -807,6 +806,9 @@ bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{
if(UIWidget::onMouseMove(mousePos, mouseMoved))
return true;
if(m_selectable && isPressed()) {
int pos = getTextPos(mousePos);
if(pos >= 0) {
@ -815,7 +817,7 @@ bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
}
return true;
}
return UIWidget::onMouseMove(mousePos, mouseMoved);
return false;
}
bool UITextEdit::onDoubleClick(const Point& mousePos)

Loading…
Cancel
Save