class EE::UI::Doc::TextDocument

Overview

#include <textdocument.hpp>

class TextDocument {
public:
    // typedefs

    typedef std::function<void()> DocumentCommand;
    typedef std::function<void(Client*)> DocumentRefCommand;

    // enums

    enum FindReplaceType;
    enum IndentType;
    enum LoadStatus;
    enum MatchDirection;
    enum UndoRedo;

    // structs

    struct SearchResult;

    // classes

    class Client;
    class SearchResults;

    // construction

    TextDocument(bool verbose = true);
    ~TextDocument();

    // methods

    bool isNonWord(String::StringBaseType ch) const;
    bool hasFilepath() const;
    bool isEmpty() const;
    bool isUntitledEmpty() const;
    void reset();
    void resetCursor();
    LoadStatus loadFromStream(IOStream& path);
    LoadStatus loadFromFile(const std::string& path);
    bool loadAsyncFromFile(const std::string& path, std::shared_ptr<ThreadPool> pool, std::function<void(TextDocument*, bool)> onLoaded = std::function<void(TextDocument*, bool success)>());
    LoadStatus loadFromMemory(const Uint8* data, const Uint32& size);
    LoadStatus loadFromPack(Pack* pack, std::string filePackPath);
    LoadStatus loadFromURL(const std::string& url, const EE::Network::Http::Request::FieldTable& headers = Http::Request::FieldTable());
    bool loadAsyncFromURL(const std::string& url, const Http::Request::FieldTable& headers = Http::Request::FieldTable(), std::function<void(TextDocument*, bool)> onLoaded = std::function<void(TextDocument*, bool success)>(), const Http::Request::ProgressCallback& progressCallback = nullptr);
    LoadStatus reload();
    bool save();
    bool save(const std::string& path);
    bool save(IOStream& stream, bool keepUndoRedoStatus = false);
    std::string getFilename() const;
    void setSelection(const TextPosition& position);
    void setSelection(const size_t& cursorIdx, TextPosition start, TextPosition end, bool swap = false);
    void setSelection(TextPosition start, TextPosition end, bool swap = false);
    void setSelection(const TextRange& range);
    TextRange getSelection(bool sort) const;
    const TextRanges& getSelections() const;
    const TextRange& getSelection() const;
    const TextRange& getSelectionIndex(const size_t& index) const;
    TextDocumentLine& line(const size_t& index);
    const TextDocumentLine& line(const size_t& index) const;
    size_t linesCount() const;
    const TextDocumentLine& getCurrentLine() const;
    bool hasSelection() const;
    const std::array<Uint8, 16>& getHash() const;
    std::string getHashHexString() const;
    String getText(const TextRange& range) const;
    String getText() const;
    String getSelectedText() const;
    String::StringBaseType getPrevChar() const;
    String::StringBaseType getCurrentChar() const;
    String::StringBaseType getChar(const TextPosition& position) const;
    String::StringBaseType getCharFromUnsanitizedPosition(const TextPosition& position) const;
    TextPosition insert(const size_t& cursorIdx, const TextPosition& position, const String& text);
    size_t remove(const size_t& cursorIdx, TextRange range);
    TextPosition positionOffset(TextPosition position, int columnOffset, bool sanitizeInput = true) const;
    TextPosition positionOffset(TextPosition position, TextPosition offset) const;
    bool replaceLine(const Int64& lineNum, const String& text);
    bool replaceCurrentLine(const String& text);
    void print() const;
    TextPosition nextChar(TextPosition position) const;
    TextPosition previousChar(TextPosition position) const;
    TextPosition previousWordBoundary(TextPosition position, bool ignoreFirstNonWord = true, std::size_t maxSeekChars = 1024, bool returnInvalidOnMaxSeek = false) const;
    TextPosition nextWordBoundary(TextPosition position, bool ignoreFirstNonWord = true, std::size_t maxSeekChars = 1024, bool returnInvalidOnMaxSeek = false) const;
    TextPosition previousSpaceBoundaryInLine(TextPosition position, std::size_t maxSeekChars = 1024, bool returnInvalidOnMaxSeek = false) const;
    TextPosition nextSpaceBoundaryInLine(TextPosition position, std::size_t maxSeekChars = 1024, bool returnInvalidOnMaxSeek = false) const;
    TextPosition startOfWord(TextPosition position) const;
    TextPosition endOfWord(TextPosition position) const;
    TextPosition startOfLine(TextPosition position) const;
    TextPosition endOfLine(TextPosition position) const;
    TextPosition startOfContent(TextPosition position);
    TextPosition startOfDoc() const;
    TextPosition endOfDoc() const;
    TextRange getDocRange() const;
    TextRange getLineRange(Int64 line) const;
    void deleteTo(const size_t& cursorIdx, TextPosition position);
    void deleteTo(const size_t& cursorIdx, int offset);
    void deleteSelection();
    void selectTo(TextPosition position);
    void selectTo(int offset);
    void moveTo(TextPosition offset);
    void moveTo(int columnOffset);
    void textInput(const String& text, bool mightBeInteresting = true);
    void pasteText(String&& text);
    void imeTextEditing(const String& text);
    void registerClient(Client* client);
    void unregisterClient(Client* client);
    void moveToPreviousChar();
    void moveToNextChar();
    void moveToPreviousWord();
    void moveToNextWord();
    void moveToPreviousLine();
    void moveToNextLine();
    void moveToPreviousPage(Int64 pageSize);
    void moveToNextPage(Int64 pageSize);
    void moveToStartOfDoc();
    void moveToEndOfDoc();
    void moveToStartOfLine();
    void moveToEndOfLine();
    void moveToStartOfContent();
    void deleteToPreviousChar();
    void deleteToNextChar();
    void deleteToPreviousWord();
    void deleteToNextWord();
    void deleteWord();
    void deleteCurrentLine();
    void selectToPreviousChar();
    void selectToNextChar();
    void selectToPreviousWord();
    void selectWord(bool withMulticursor = true);
    void selectAllWords();
    void selectLine();
    void selectSingleLine();
    void selectToNextWord();
    void selectToPreviousLine();
    void selectToNextLine();
    void selectToStartOfLine();
    void selectToEndOfLine();
    void selectToStartOfDoc();
    void selectToEndOfDoc();
    void selectToPreviousPage(Int64 pageSize);
    void selectToNextPage(Int64 pageSize);
    void selectToStartOfContent();
    void selectAll();
    void newLine();
    void newLineAbove();
    void indent();
    void unindent();
    void moveLinesUp();
    void moveLinesDown();
    bool hasUndo() const;
    bool hasRedo() const;
    void undo();
    void redo();
    void execute(const std::string& command);
    void execute(const std::string& command, Client* client);
    void setCommands(const UnorderedMap<std::string, DocumentCommand>& cmds);
    void setCommand(const std::string& command, const DocumentCommand& func);
    void setCommand(const std::string& command, const DocumentRefCommand& func);
    bool hasCommand(const std::string& command);
    bool removeCommand(const std::string& command);
    SearchResult find(const String& text, TextPosition from = { 0, 0 }, bool caseSensitive = true, bool wholeWord = false, FindReplaceType type = FindReplaceType::Normal, TextRange restrictRange = TextRange());
    SearchResult findLast(const String& text, TextPosition from = { 0, 0 }, bool caseSensitive = true, bool wholeWord = false, FindReplaceType type = FindReplaceType::Normal, TextRange restrictRange = TextRange());
    SearchResults findAll(const String& text, bool caseSensitive = true, bool wholeWord = false, FindReplaceType type = FindReplaceType::Normal, TextRange restrictRange = TextRange(), size_t maxResults = 0);
    int replaceAll(const String& text, const String& replace, const bool& caseSensitive = true, const bool& wholeWord = false, FindReplaceType type = FindReplaceType::Normal, TextRange restrictRange = TextRange());
    TextPosition replaceSelection(const String& replace);

    TextPosition replace(
        String search,
        const String& replace,
        TextPosition from = { 0, 0 },
        const bool& caseSensitive = true,
        const bool& wholeWord = false,
        FindReplaceType type = FindReplaceType::Normal,
        TextRange restrictRange = TextRange()
    );

    String getIndentString();
    const Uint32& getIndentWidth() const;
    void setIndentWidth(const Uint32& tabWidth);
    TextPosition sanitizePosition(const TextPosition& position) const;
    const IndentType& getIndentType() const;
    void setIndentType(const IndentType& indentType);
    const SyntaxDefinition& getSyntaxDefinition() const;
    void setSyntaxDefinition(const SyntaxDefinition& definition);
    Uint64 getCurrentChangeId() const;
    const std::string& getDefaultFileName() const;
    void setDefaultFileName(const std::string& defaultFileName);
    const std::string& getFilePath() const;
    const URI& getURI() const;
    const FileInfo& getFileInfo() const;
    bool isDirty() const;
    const Uint32& getPageSize() const;
    void setPageSize(const Uint32& pageSize);
    const String& getNonWordChars() const;
    void toggleLineComments();
    void setNonWordChars(const String& nonWordChars);
    const SyntaxDefinition& guessSyntax() const;
    void resetSyntax();
    bool getAutoDetectIndentType() const;
    void setAutoDetectIndentType(bool autodetect);
    const TextFormat::LineEnding& getLineEnding() const;
    void setLineEnding(const TextFormat::LineEnding& lineEnding);
    bool getForceNewLineAtEndOfFile() const;
    void setForceNewLineAtEndOfFile(bool forceNewLineAtEndOfFile);
    bool getTrimTrailingWhitespaces() const;
    void setTrimTrailingWhitespaces(bool trimTrailingWhitespaces);
    Client* getActiveClient() const;
    void setActiveClient(Client* activeClient);
    void setBOM(bool active);
    bool isBOM() const;
    TextRange sanitizeRange(const TextRange& range) const;
    TextRanges sanitizeRange(const TextRanges& ranges) const;
    bool isValidPosition(const TextPosition& position) const;
    bool isValidRange(const TextRange& range) const;
    bool getAutoCloseBrackets() const;
    void setAutoCloseBrackets(bool autoCloseBrackets);
    const std::vector<std::pair<String::StringBaseType, String::StringBaseType>>& getAutoCloseBracketsPairs() const;
    void setAutoCloseBracketsPairs(const std::vector<std::pair<String::StringBaseType, String::StringBaseType>>& autoCloseBracketsPairs);
    bool isDirtyOnFileSystem() const;
    void setDirtyOnFileSystem(bool dirtyOnFileSystem);
    bool isSaving() const;
    void sanitizeCurrentSelection();
    bool isLoading() const;
    bool isDeleteOnClose() const;
    void setDeleteOnClose(bool deleteOnClose);
    bool hasSyntaxDefinition() const;
    void notifyDocumentMoved(const std::string& newPath);
    void toUpperSelection();
    void toLowerSelection();
    std::string getLoadingFilePath() const;
    URI getLoadingFileURI() const;
    void setSelection(const TextRanges& selection);
    void resetSelection(const TextRanges& selection);
    TextRanges getSelectionsSorted() const;
    void addCursorAbove();
    void addCursorBelow();
    TextRange getTopMostCursor();
    TextRange getBottomMostCursor();
    void moveTo(const size_t& cursorIdx, TextPosition offset);
    void moveTo(const size_t& cursorIdx, int columnOffset);
    void setSelection(const size_t& cursorIdx, const TextPosition& position);
    void mergeSelection();
    void selectTo(const size_t& cursorIdx, TextPosition position);
    void selectTo(const size_t& cursorIdx, int offset);
    void setSelection(const size_t& cursorIdx, const TextRange& range);
    TextRange addSelection(TextRange selection);
    TextRange addSelection(const TextPosition& selection);
    TextRange addSelections(TextRanges&& selections);
    void popSelection();
    void deleteSelection(const size_t& cursorIdx);
    String getSelectedText(const size_t& cursorIdx) const;
    size_t getLastSelection() const;
    bool selectionExists(const TextRange& selection);
    bool selectionExists(const TextPosition& selection);
    TextPosition replaceSelection(const size_t& cursorIdx, const String& replace);
    void cursorUndo();
    void selectAllMatches();
    String getAllSelectedText() const;
    std::vector<std::string> getCommandList() const;
    bool isRunningTransaction() const;
    void setRunningTransaction(const bool runningTransaction);
    TextPosition getMatchingBracket(TextPosition startPosition, const String::StringBaseType& openBracket, const String::StringBaseType& closeBracket, MatchDirection dir, bool allowDepth = true);
    TextRange getMatchingBracket(TextPosition startPosition, const String& openBracket, const String& closeBracket, MatchDirection dir, bool matchingXMLTags = false);
    SyntaxHighlighter* getHighlighter() const;
    TextRange getWordRangeInPosition(const TextPosition& pos, bool basedOnHighlighter = true);
    TextRange getWordRangeInPosition(bool basedOnHighlighter = true);
    String getWordInPosition(const TextPosition& pos, bool basedOnHighlighter = true);
    String getWordInPosition(bool basedOnHighlighter = true);
    bool mightBeBinary() const;
    void setMightBeBinary(bool mightBeBinary);
    TextRange getActiveClientVisibleRange() const;
    bool hAsCpp() const;
    void setHAsCpp(bool hAsCpp);
    const Uint64& getModificationId() const;
    void stopActiveFindAll();
    bool isDoingTextInput() const;
    bool isInsertingText() const;
    void resetUndoRedo();
    TextFormat::Encoding getEncoding() const;
    void setEncoding(TextFormat::Encoding encoding);
    const FoldRangeServive& getFoldRangeService() const;
    FoldRangeServive& getFoldRangeService();
    std::vector<TextDocumentLine> getLines() const;
    void setLines(std::vector<TextDocumentLine>&& lines);
    std::string serializeUndoRedo(bool inverted);
    void unserializeUndoRedo(const std::string& jsonString);
    void changeFilePath(const std::string& filePath);
    void setDirtyUntilSave();
    bool isHuge() const;
};

Detailed Documentation

Methods

LoadStatus loadFromURL(const std::string& url, const EE::Network::Http::Request::FieldTable& headers = Http::Request::FieldTable())

loadFromURL

Parameters:

url

Resources URL.

headers

Key value map of headers

Returns: