Skip to content

Commit

Permalink
Fix: update console after clearWindow(...) (Mudlet#7465)
Browse files Browse the repository at this point in the history
#### Brief overview of PR changes/additions
Clean up the distribution of code associated with clearing a `TConsole`
amongst the classes and add extra calls to methods that remove the
display of the lower `TTextEdit` (i.e. remove the split) and ensure that
the upper one is redrawn after the contents have been removed.

#### Motivation for adding to Mudlet
This - not clearing the lower pane and the split even though all the
data has gone so there is no need for the split - has been an issue
(though not recorded as one) for a long time as far as I can determine.

#### Other info (issues closed, discussion etc)
This should close Mudlet#7463.

Signed-off-by: Stephen Lyons <[email protected]>
  • Loading branch information
SlySven authored Oct 14, 2024
1 parent dbd3fcf commit 71eee4b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
12 changes: 2 additions & 10 deletions src/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,22 +3305,14 @@ bool Host::createBuffer(const QString& name)
return false;
}


// Doesn't work on the errors or central debug consoles:
bool Host::clearWindow(const QString& name)
{
if (!mpConsole) {
return false;
}

auto pC = mpConsole->mSubConsoleMap.value(name);
if (pC) {
pC->mUpperPane->resetHScrollbar();
pC->buffer.clear();
pC->mUpperPane->update();
return true;
} else {
return false;
}
return mpConsole->clear(name);
}

bool Host::showWindow(const QString& name)
Expand Down
9 changes: 9 additions & 0 deletions src/TConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,15 @@ void TConsole::refresh()
QApplication::sendEvent(this, &event);
}

void TConsole::clear()
{
mUpperPane->resetHScrollbar();
buffer.clear();
clearSplit();
mUpperPane->update();
mLowerPane->update();
}

void TConsole::clearSelection() const
{
mLowerPane->unHighlight();
Expand Down
1 change: 1 addition & 0 deletions src/TConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class TConsole : public QWidget
void copy();
void cut();
void paste();
void clear();
void appendBuffer();
void appendBuffer(const TBuffer&);
int getButtonState();
Expand Down
19 changes: 9 additions & 10 deletions src/TLuaInterpreterUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,20 @@ int TLuaInterpreter::calcFontSize(lua_State* L)
}

// Documentation: https://wiki.mudlet.org/w/Manual:Lua_Functions#clearUserWindow
// Note that this is registered as both clearUserWindow(...) AND clearWindow(...)
int TLuaInterpreter::clearUserWindow(lua_State* L)
{
if (!lua_isstring(L, 1)) {
const Host& host = getHostFromLua(L);
host.mpConsole->mUpperPane->resetHScrollbar();
host.mpConsole->buffer.clear();
host.mpConsole->mUpperPane->showNewLines();
//host.mpConsole->mUpperPane->forceUpdate();
return 0;
QString windowName;
if (lua_gettop(L)) {
windowName = getVerifiedString(L, __func__, 1, "window name", true);
}
const QString text = lua_tostring(L, 1);

Host& host = getHostFromLua(L);
host.clearWindow(text);

host.clearWindow(windowName);
// Note that exceptionally THIS function does not return a true/nil+error
// message on failure - because on success this could plonk a "true" on the
// main screen if run from the command line - which sort of messes with the
// idea of clearing it of text!
return 0;
}

Expand Down
19 changes: 19 additions & 0 deletions src/TMainConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,3 +1641,22 @@ void TMainConsole::closeEvent(QCloseEvent* event)
event->accept();
}
}

bool TMainConsole::clear(const QString& name)
{
if (name.isEmpty() || !name.compare(QLatin1String("main"))) {
TConsole::clear();
mUpperPane->showNewLines();
mUpperPane->forceUpdate();
mLowerPane->forceUpdate();
return true;
}

auto pC = mSubConsoleMap.value(name);
if (pC) {
pC->clear();
return true;
}

return false;
}
1 change: 1 addition & 0 deletions src/TMainConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TMainConsole : public TConsole
bool showWindow(const QString& name);
bool hideWindow(const QString& name);
bool printWindow(const QString& name, const QString& text);
bool clear(const QString& name);
void setProfileName(const QString&) override;
void selectCurrentLine(std::string&);
std::list<int> getFgColor(std::string& buf);
Expand Down

0 comments on commit 71eee4b

Please sign in to comment.