From 4f7899ca14b94afdc8c2b3cdf3c0ca15eae27651 Mon Sep 17 00:00:00 2001 From: Michael Kazakov Date: Mon, 17 Jun 2024 20:25:50 +0100 Subject: [PATCH] Added syntax settings for XML --- .../Resources/SyntaxHighlighting/Main.json | 5 +++ .../Resources/SyntaxHighlighting/XML.json | 35 +++++++++++++++++++ .../include/Viewer/Highlighting/Document.h | 1 + .../Viewer/source/Highlighting/Document.cpp | 26 ++++++++------ 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json diff --git a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json index 0d1be33d2..edcebed7c 100644 --- a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json +++ b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json @@ -20,6 +20,11 @@ "settings": "Markdown.json", "filemask": "*.md, *.markdown" }, + { + "name": "XML", + "settings": "XML.json", + "filemask": "*.xml, *.plist" + }, { "name": "YAML", "settings": "YAML.json", diff --git a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json new file mode 100644 index 000000000..6176fb7f3 --- /dev/null +++ b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json @@ -0,0 +1,35 @@ +{ + "lexer": "xml", + "wordlists": [], + "properties": { + }, + "mapping": { + "SCE_H_DEFAULT": "default", + "SCE_H_TAG": "keyword", + "SCE_H_TAGUNKNOWN": "comment", + "SCE_H_ATTRIBUTE": "identifier", + "SCE_H_ATTRIBUTEUNKNOWN": "comment", + "SCE_H_NUMBER": "number", + "SCE_H_DOUBLESTRING": "string", + "SCE_H_SINGLESTRING": "string", + "SCE_H_OTHER": "operator", + "SCE_H_COMMENT": "comment", + "SCE_H_ENTITY": "identifier", + "SCE_H_TAGEND": "default", + "SCE_H_XMLSTART": "comment", + "SCE_H_XMLEND": "comment", + "SCE_H_CDATA": "string", + "SCE_H_QUESTION": "preprocessor", + "SCE_H_VALUE": "default", + "SCE_H_SGML_DEFAULT": "default", + "SCE_H_SGML_COMMAND": "preprocessor", + "SCE_H_SGML_1ST_PARAM": "preprocessor", + "SCE_H_SGML_DOUBLESTRING": "string", + "SCE_H_SGML_SIMPLESTRING": "string", + "SCE_H_SGML_ERROR": "comment", + "SCE_H_SGML_SPECIAL": "identifier", + "SCE_H_SGML_ENTITY": "identifier", + "SCE_H_SGML_COMMENT": "comment", + "SCE_H_SGML_BLOCK_DEFAULT": "default" + } +} diff --git a/Source/Viewer/include/Viewer/Highlighting/Document.h b/Source/Viewer/include/Viewer/Highlighting/Document.h index 9f45f93a3..871a114c2 100644 --- a/Source/Viewer/include/Viewer/Highlighting/Document.h +++ b/Source/Viewer/include/Viewer/Highlighting/Document.h @@ -72,6 +72,7 @@ class Document final : public Scintilla::IDocument std::string_view m_Text; std::vector m_Lines; std::vector m_LineStates; + std::vector m_LineLevels; std::vector m_Styles; Sci_Position m_StylingPosition = 0; }; diff --git a/Source/Viewer/source/Highlighting/Document.cpp b/Source/Viewer/source/Highlighting/Document.cpp index b9d2e3ccd..9f2b09e9b 100644 --- a/Source/Viewer/source/Highlighting/Document.cpp +++ b/Source/Viewer/source/Highlighting/Document.cpp @@ -9,6 +9,7 @@ namespace nc::viewer::hl { static constexpr char g_CR = '\x0D'; static constexpr char g_LF = '\x0A'; +static constexpr int g_BaseLevel = 0x400; static constinit std::array g_UTF8Lengths = []() { std::array lengths = {}; @@ -90,6 +91,7 @@ Document::Document(const std::string_view _text) : m_Text(_text), m_Styles(_text } m_LineStates.resize(m_Lines.size() + 1); + m_LineLevels.resize(m_Lines.size(), g_BaseLevel); } Document::~Document() = default; @@ -109,7 +111,7 @@ bool Document::IsDBCSLeadByte(char) const noexcept return false; } -char Document::StyleAt(Sci_Position _position) const noexcept +char Document::StyleAt(const Sci_Position _position) const noexcept { if( _position < 0 || _position >= static_cast(m_Text.length()) ) { return 0; @@ -117,24 +119,26 @@ char Document::StyleAt(Sci_Position _position) const noexcept return m_Styles[_position]; } -int Document::GetLevel(Sci_Position /*_line*/) const noexcept +int Document::GetLevel(const Sci_Position _line) const noexcept { - abort(); - return 0; + return _line >= 0 && static_cast(_line) < m_LineLevels.size() ? m_LineLevels[_line] : g_BaseLevel; } -int Document::SetLevel(Sci_Position /*_line*/, int /*_level*/) noexcept +int Document::SetLevel(const Sci_Position _line, const int _level) noexcept { - abort(); - return 0; + if( _line >= 0 && static_cast(_line) < m_LineLevels.size() ) { + m_LineLevels[_line] = _level; + return _level; + } + return g_BaseLevel; } -int Document::GetLineState(Sci_Position _line) const noexcept +int Document::GetLineState(const Sci_Position _line) const noexcept { return m_LineStates.at(_line); } -int Document::SetLineState(Sci_Position _line, int _state) noexcept +int Document::SetLineState(const Sci_Position _line, const int _state) noexcept { return m_LineStates.at(_line) = _state; } @@ -145,9 +149,9 @@ int Document::GetLineIndentation(Sci_Position /*_line*/) noexcept return 0; } -Sci_Position Document::GetRelativePosition(Sci_Position _position, Sci_Position _offset) const noexcept +Sci_Position Document::GetRelativePosition(const Sci_Position _position, const Sci_Position _offset) const noexcept { - return _position + _offset; + return _position + _offset; // TODO: is _offset in bytes or in code units? } int Document::GetCharacterAndWidth(Sci_Position _position, Sci_Position *_width) const noexcept