From 4012f14e6397f5709586102540df824d8c9ca4a5 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 7 Apr 2011 21:26:47 +1000 Subject: =?UTF-8?q?Add=20highlighting=20of=20current=20folding=20block.=20?= =?UTF-8?q?Feature=20#3147069.=20APIs=20MarkerEnableHighlight=20and=20Mark?= =?UTF-8?q?erSetBackSelected.=20From=20J=C3=A9r=C3=B4me=20Laforge.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Document.cxx | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'src/Document.cxx') diff --git a/src/Document.cxx b/src/Document.cxx index e573e1906..f74ac5830 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -355,6 +355,104 @@ int Document::GetFoldParent(int line) { } } +void Document::GetHighlightDelimiters(int line, HighlightDelimiter &highlightDelimiter) { + int endLine = LineFromPosition(Length()); + int beginFoldBlock = -1; + int endFoldBlock = -1; + int beginMarginCorrectlyDrawnZone = -1; + int endMarginCorrectlyDrawnZone = endLine + 1; + int endOfTailOfWhiteFlag = -1; //endOfTailOfWhiteFlag points the last SC_FOLDLEVELWHITEFLAG if follow a fold block. Otherwise endOfTailOfWhiteFlag points end of fold block. + int level = GetLevel(line); + int levelNumber = -1; + int lineLookLevel = -1; + int lineLookLevelNumber = -1; + int lineLook = line; + bool beginFoldBlockFound = false; + bool endFoldBlockFound = false; + bool beginMarginCorrectlyDrawnZoneFound = false; + bool endMarginCorrectlyDrawnZoneFound = false; + + /*******************************************************************************/ + /* search backward (beginFoldBlock & beginMarginCorrectlyDrawnZone) */ + /*******************************************************************************/ + for (endOfTailOfWhiteFlag = line; lineLook >= 0 && (!beginFoldBlockFound || !beginMarginCorrectlyDrawnZoneFound); --lineLook) { + lineLookLevel = GetLevel(lineLook); + if (levelNumber != -1) { + lineLookLevelNumber = lineLookLevel & SC_FOLDLEVELNUMBERMASK; + if (!beginMarginCorrectlyDrawnZoneFound && (lineLookLevelNumber > levelNumber)) { + beginMarginCorrectlyDrawnZoneFound = true; + beginMarginCorrectlyDrawnZone = endOfTailOfWhiteFlag; + } + //find the last space line (SC_FOLDLEVELWHITEFLAG). + if (!beginMarginCorrectlyDrawnZoneFound && !(lineLookLevel & SC_FOLDLEVELWHITEFLAG)) { + endOfTailOfWhiteFlag = lineLook - 1; + } + if (!beginFoldBlockFound && (lineLookLevelNumber < levelNumber)) { + beginFoldBlockFound = true; + beginFoldBlock = lineLook; + if (!beginMarginCorrectlyDrawnZoneFound) { + beginMarginCorrectlyDrawnZoneFound = true; + beginMarginCorrectlyDrawnZone = lineLook - 1; + } + } else if (!beginFoldBlockFound && lineLookLevelNumber == SC_FOLDLEVELBASE) { + beginFoldBlockFound = true; //beginFoldBlock already set to -1. + } + } else if (!(lineLookLevel & SC_FOLDLEVELWHITEFLAG)) { + endOfTailOfWhiteFlag = lineLook - 1; + if (lineLookLevel & SC_FOLDLEVELHEADERFLAG) { + beginFoldBlockFound = true; + beginFoldBlock = lineLook; + beginMarginCorrectlyDrawnZoneFound = true; + beginMarginCorrectlyDrawnZone = endOfTailOfWhiteFlag; + levelNumber = GetLevel(lineLook + 1) & SC_FOLDLEVELNUMBERMASK;; + } else { + levelNumber = lineLookLevel & SC_FOLDLEVELNUMBERMASK; + } + } + } + + /****************************************************************************/ + /* search forward (endStartBlock & endMarginCorrectlyDrawnZone) */ + /****************************************************************************/ + if (level & SC_FOLDLEVELHEADERFLAG) { + //ignore this line because this line is on first one of block. + lineLook = line + 1; + } else { + lineLook = line; + } + for (; lineLook <= endLine && (!endFoldBlockFound || !endMarginCorrectlyDrawnZoneFound); ++lineLook) { + lineLookLevel = GetLevel(lineLook); + lineLookLevelNumber = lineLookLevel & SC_FOLDLEVELNUMBERMASK; + if (!endFoldBlockFound && !(lineLookLevel & SC_FOLDLEVELWHITEFLAG) && lineLookLevelNumber < levelNumber) { + endFoldBlockFound = true; + endFoldBlock = lineLook - 1; + if (!endMarginCorrectlyDrawnZoneFound) { + endMarginCorrectlyDrawnZoneFound = true; + endMarginCorrectlyDrawnZone = lineLook; + } + } else if (!endFoldBlockFound && lineLookLevel == SC_FOLDLEVELBASE) { + endFoldBlockFound = true; + endFoldBlock = -1; + } + if (!endMarginCorrectlyDrawnZoneFound && (lineLookLevel & SC_FOLDLEVELHEADERFLAG)) { + endMarginCorrectlyDrawnZoneFound = true; + endMarginCorrectlyDrawnZone = lineLook; + } + } + if (!endFoldBlockFound && ((lineLook > endLine && lineLookLevelNumber < levelNumber) || + (levelNumber > SC_FOLDLEVELBASE))) { + //manage when endfold is incorrect or on last line. + endFoldBlock = lineLook - 1; + //useless to set endMarginCorrectlyDrawnZone. + //if endMarginCorrectlyDrawnZoneFound equals false then endMarginCorrectlyDrawnZone already equals to endLine + 1. + } + + highlightDelimiter.beginFoldBlock = beginFoldBlock; + highlightDelimiter.endFoldBlock = endFoldBlock; + highlightDelimiter.beginMarginCorrectlyDrawnZone = beginMarginCorrectlyDrawnZone; + highlightDelimiter.endMarginCorrectlyDrawnZone = endMarginCorrectlyDrawnZone; +} + int Document::ClampPositionIntoDocument(int pos) { return Platform::Clamp(pos, 0, Length()); } -- cgit v1.2.3