summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/Command.h3
-rw-r--r--Libraries/LibGUI/TextDocument.cpp12
-rw-r--r--Libraries/LibGUI/TextDocument.h6
-rw-r--r--Libraries/LibGUI/TextEditor.cpp9
4 files changed, 22 insertions, 8 deletions
diff --git a/Libraries/LibGUI/Command.h b/Libraries/LibGUI/Command.h
index 9ff6a0aad9..3b2f081a6a 100644
--- a/Libraries/LibGUI/Command.h
+++ b/Libraries/LibGUI/Command.h
@@ -39,6 +39,9 @@ public:
String action_text() const { return m_action_text; }
+ virtual bool is_insert_text() const { return false; }
+ virtual bool is_remove_text() const { return false; }
+
protected:
Command() { }
void set_action_text(const String& text) { m_action_text = text; }
diff --git a/Libraries/LibGUI/TextDocument.cpp b/Libraries/LibGUI/TextDocument.cpp
index 10a5ffe497..35abe1e3ac 100644
--- a/Libraries/LibGUI/TextDocument.cpp
+++ b/Libraries/LibGUI/TextDocument.cpp
@@ -282,6 +282,18 @@ void TextDocument::set_all_cursors(const TextPosition& position)
}
}
+String TextDocument::text() const
+{
+ StringBuilder builder;
+ for (size_t i = 0; i < line_count(); ++i) {
+ auto& line = this->line(i);
+ builder.append(line.view());
+ if (i != line_count() - 1)
+ builder.append('\n');
+ }
+ return builder.to_string();
+}
+
String TextDocument::text_in_range(const TextRange& a_range) const
{
auto range = a_range.normalized();
diff --git a/Libraries/LibGUI/TextDocument.h b/Libraries/LibGUI/TextDocument.h
index 85fad0e97a..e6ee731ceb 100644
--- a/Libraries/LibGUI/TextDocument.h
+++ b/Libraries/LibGUI/TextDocument.h
@@ -103,6 +103,7 @@ public:
void update_views(Badge<TextDocumentLine>);
+ String text() const;
String text_in_range(const TextRange&) const;
Vector<TextRange> find_all(const StringView& needle) const;
@@ -210,6 +211,9 @@ public:
InsertTextCommand(TextDocument&, const String&, const TextPosition&);
virtual void undo() override;
virtual void redo() override;
+ virtual bool is_insert_text() const override { return true; }
+ const String& text() const { return m_text; }
+ const TextRange& range() const { return m_range; }
private:
String m_text;
@@ -221,6 +225,8 @@ public:
RemoveTextCommand(TextDocument&, const String&, const TextRange&);
virtual void undo() override;
virtual void redo() override;
+ virtual bool is_remove_text() const override { return true; }
+ const TextRange& range() const { return m_range; }
private:
String m_text;
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp
index f67d04cf72..07593715cb 100644
--- a/Libraries/LibGUI/TextEditor.cpp
+++ b/Libraries/LibGUI/TextEditor.cpp
@@ -1254,14 +1254,7 @@ bool TextEditor::write_to_file(const StringView& path)
String TextEditor::text() const
{
- StringBuilder builder;
- for (size_t i = 0; i < line_count(); ++i) {
- auto& line = this->line(i);
- builder.append(line.view());
- if (i != line_count() - 1)
- builder.append('\n');
- }
- return builder.to_string();
+ return document().text();
}
void TextEditor::clear()