diff options
| author | Neil <nyamatongwe@gmail.com> | 2014-08-08 10:01:55 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2014-08-08 10:01:55 +1000 | 
| commit | a2940fd23daf6f8d82c9c821de5c40077ce0da84 (patch) | |
| tree | c90f4a2d63322446821db40a6df3a0106b751035 /src/PerLine.cxx | |
| parent | 0f69f3794f88db0630d7264c26c557558ed44b60 (diff) | |
| download | scintilla-mirror-a2940fd23daf6f8d82c9c821de5c40077ce0da84.tar.gz | |
Implement explicit tab stops per line.
From Nick Gravgaard.
Diffstat (limited to 'src/PerLine.cxx')
| -rw-r--r-- | src/PerLine.cxx | 70 | 
1 files changed, 70 insertions, 0 deletions
| diff --git a/src/PerLine.cxx b/src/PerLine.cxx index 8b0dbc44b..8fd96cbed 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -7,6 +7,7 @@  #include <string.h> +#include <vector>  #include <algorithm>  #include "Platform.h" @@ -484,3 +485,72 @@ int LineAnnotation::Lines(int line) const {  	else  		return 0;  } + +LineTabstops::~LineTabstops() { +	Init(); +} + +void LineTabstops::Init() { +	for (int line = 0; line < tabstops.Length(); line++) { +		delete tabstops[line]; +	} +	tabstops.DeleteAll(); +} + +void LineTabstops::InsertLine(int line) { +	if (tabstops.Length()) { +		tabstops.EnsureLength(line); +		tabstops.Insert(line, 0); +	} +} + +void LineTabstops::RemoveLine(int line) { +	if (tabstops.Length() > line) { +		delete tabstops[line]; +		tabstops.Delete(line); +	} +} + +bool LineTabstops::ClearTabstops(int line) { +	if (line < tabstops.Length()) { +		TabstopList *tl = tabstops[line]; +		if (tl) { +			tl->clear(); +			return true; +		} +	} +	return false; +} + +bool LineTabstops::AddTabstop(int line, int x) { +	tabstops.EnsureLength(line + 1); +	if (!tabstops[line]) { +		tabstops[line] = new TabstopList(); +	} + +	TabstopList *tl = tabstops[line]; +	if (tl) { +		// tabstop positions are kept in order - insert in the right place +		std::vector<int>::iterator it = std::lower_bound(tl->begin(), tl->end(), x); +		// don't insert duplicates +		if (it == tl->end() || *it != x) { +			tl->insert(it, x); +			return true; +		} +	} +	return false; +} + +int LineTabstops::GetNextTabstop(int line, int x) const { +	if (line < tabstops.Length()) { +		TabstopList *tl = tabstops[line]; +		if (tl) { +			for (size_t i = 0; i < tl->size(); i++) { +				if ((*tl)[i] > x) { +					return (*tl)[i]; +				} +			} +		} +	} +	return 0; +} | 
