aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx151
-rw-r--r--src/Editor.h2
-rw-r--r--src/Style.h2
-rw-r--r--src/ViewStyle.cxx9
-rw-r--r--src/ViewStyle.h2
5 files changed, 108 insertions, 58 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 8f5918bd1..aa2f82435 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -843,18 +843,45 @@ void Editor::SetEmptySelection(int currentPos_) {
SetSelection(currentPos_, currentPos_);
}
+bool Editor::RangeContainsProtected(int start, int end) const {
+ if (vs.ProtectionActive()) {
+ if (start > end) {
+ int t = start;
+ start = end;
+ end = t;
+ }
+ int mask = pdoc->stylingBitsMask;
+ for (int pos = start; pos < end; pos++) {
+ if (vs.styles[pdoc->StyleAt(pos) & mask].IsProtected())
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Editor::SelectionContainsProtected() const {
+ // TODO: make support rectangular selection
+ return RangeContainsProtected(anchor, currentPos);
+}
+
int Editor::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {
// Asks document to find a good position and then moves out of any invisible positions
pos = pdoc->MovePositionOutsideChar(pos, moveDir, checkLineEnd);
- int mask = pdoc->stylingBitsMask;
- if (moveDir > 0) {
- while ((pos < pdoc->Length()) &&
- (vs.styles[pdoc->StyleAt(pos - 1) & mask].IsProtected()))
- pos++;
- } else {
- while ((pos > 0) &&
- (vs.styles[pdoc->StyleAt(pos - 1) & mask].IsProtected()))
- pos--;
+ if (vs.ProtectionActive()) {
+ int mask = pdoc->stylingBitsMask;
+ if (moveDir > 0) {
+ if ((pos > 0) && vs.styles[pdoc->StyleAt(pos-1) & mask].IsProtected()) {
+ while ((pos < pdoc->Length()) &&
+ (vs.styles[pdoc->StyleAt(pos) & mask].IsProtected()))
+ pos++;
+ }
+ } else if (moveDir < 0) {
+ if (vs.styles[pdoc->StyleAt(pos) & mask].IsProtected()) {
+ while ((pos > 0) &&
+ (vs.styles[pdoc->StyleAt(pos-1) & mask].IsProtected()))
+ pos--;
+ }
+ }
}
return pos;
}
@@ -2038,14 +2065,16 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis
}
} else {
// Normal text display
- if (twoPhaseDraw) {
- surface->DrawTextTransparent(rcSegment, textFont,
- rcSegment.top + vsDraw.maxAscent, ll->chars + startseg,
- i - startseg + 1, textFore);
- } else {
- surface->DrawTextNoClip(rcSegment, textFont,
- rcSegment.top + vsDraw.maxAscent, ll->chars + startseg,
- i - startseg + 1, textFore, textBack);
+ if (vsDraw.styles[styleMain].visible) {
+ if (twoPhaseDraw) {
+ surface->DrawTextTransparent(rcSegment, textFont,
+ rcSegment.top + vsDraw.maxAscent, ll->chars + startseg,
+ i - startseg + 1, textFore);
+ } else {
+ surface->DrawTextNoClip(rcSegment, textFont,
+ rcSegment.top + vsDraw.maxAscent, ll->chars + startseg,
+ i - startseg + 1, textFore, textBack);
+ }
}
if (vsDraw.viewWhitespace != wsInvisible ||
(inIndentation && vsDraw.viewIndentationGuides)) {
@@ -2712,7 +2741,7 @@ void Editor::AddChar(char ch) {
void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
bool wasSelection = currentPos != anchor;
ClearSelection();
- if (inOverstrike && !wasSelection) {
+ if (inOverstrike && !wasSelection && !RangeContainsProtected(currentPos, currentPos+1)) {
if (currentPos < (pdoc->Length() - 1)) {
if ((pdoc->CharAt(currentPos) != '\r') && (pdoc->CharAt(currentPos) != '\n')) {
pdoc->DelChar(currentPos);
@@ -2766,30 +2795,32 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
}
void Editor::ClearSelection() {
- if (selType == selRectangle) {
- pdoc->BeginUndoAction();
- int lineStart = pdoc->LineFromPosition(SelectionStart());
- int lineEnd = pdoc->LineFromPosition(SelectionEnd());
- int startPos = SelectionStart();
- for (int line = lineEnd; line >= lineStart; line--) {
- startPos = SelectionStart(line);
- unsigned int chars = SelectionEnd(line) - startPos;
+ if (!SelectionContainsProtected()) {
+ if (selType == selRectangle) {
+ pdoc->BeginUndoAction();
+ int lineStart = pdoc->LineFromPosition(SelectionStart());
+ int lineEnd = pdoc->LineFromPosition(SelectionEnd());
+ int startPos = SelectionStart();
+ for (int line = lineEnd; line >= lineStart; line--) {
+ startPos = SelectionStart(line);
+ unsigned int chars = SelectionEnd(line) - startPos;
+ if (0 != chars) {
+ pdoc->DeleteChars(startPos, chars);
+ }
+ }
+ SetEmptySelection(startPos);
+ pdoc->EndUndoAction();
+ selType = selStream;
+ } else {
+ int startPos = SelectionStart();
+ unsigned int chars = SelectionEnd() - startPos;
+ SetEmptySelection(startPos);
if (0 != chars) {
+ pdoc->BeginUndoAction();
pdoc->DeleteChars(startPos, chars);
+ pdoc->EndUndoAction();
}
}
- SetEmptySelection(startPos);
- pdoc->EndUndoAction();
- selType = selStream;
- } else {
- int startPos = SelectionStart();
- unsigned int chars = SelectionEnd() - startPos;
- SetEmptySelection(startPos);
- if (0 != chars) {
- pdoc->BeginUndoAction();
- pdoc->DeleteChars(startPos, chars);
- pdoc->EndUndoAction();
- }
}
}
@@ -2816,14 +2847,14 @@ void Editor::ClearDocumentStyle() {
}
void Editor::Cut() {
- if (!pdoc->IsReadOnly()) {
+ if (!pdoc->IsReadOnly() && !SelectionContainsProtected()) {
Copy();
ClearSelection();
}
}
void Editor::PasteRectangular(int pos, const char *ptr, int len) {
- if (pdoc->IsReadOnly()) {
+ if (pdoc->IsReadOnly() || SelectionContainsProtected()) {
return;
}
currentPos = pos;
@@ -2861,12 +2892,14 @@ void Editor::PasteRectangular(int pos, const char *ptr, int len) {
}
bool Editor::CanPaste() {
- return !pdoc->IsReadOnly();
+ return !pdoc->IsReadOnly() && !SelectionContainsProtected();
}
void Editor::Clear() {
if (currentPos == anchor) {
- DelChar();
+ if (!RangeContainsProtected(currentPos, currentPos+1)) {
+ DelChar();
+ }
} else {
ClearSelection();
}
@@ -2896,29 +2929,33 @@ void Editor::Redo() {
}
void Editor::DelChar() {
- pdoc->DelChar(currentPos);
+ if (!RangeContainsProtected(currentPos, currentPos+1)) {
+ pdoc->DelChar(currentPos);
+ }
// Avoid blinking during rapid typing:
ShowCaretAtCurrentPosition();
}
void Editor::DelCharBack(bool allowLineStartDeletion) {
if (currentPos == anchor) {
- int lineCurrentPos = pdoc->LineFromPosition(currentPos);
- if (allowLineStartDeletion || (pdoc->LineStart(lineCurrentPos) != currentPos)) {
- if (pdoc->GetColumn(currentPos) <= pdoc->GetLineIndentation(lineCurrentPos) &&
- pdoc->GetColumn(currentPos) > 0 && pdoc->backspaceUnindents) {
- pdoc->BeginUndoAction();
- int indentation = pdoc->GetLineIndentation(lineCurrentPos);
- int indentationStep = (pdoc->indentInChars ? pdoc->indentInChars : pdoc->tabInChars);
- if (indentation % indentationStep == 0) {
- pdoc->SetLineIndentation(lineCurrentPos, indentation - indentationStep);
+ if (!RangeContainsProtected(currentPos-1, currentPos)) {
+ int lineCurrentPos = pdoc->LineFromPosition(currentPos);
+ if (allowLineStartDeletion || (pdoc->LineStart(lineCurrentPos) != currentPos)) {
+ if (pdoc->GetColumn(currentPos) <= pdoc->GetLineIndentation(lineCurrentPos) &&
+ pdoc->GetColumn(currentPos) > 0 && pdoc->backspaceUnindents) {
+ pdoc->BeginUndoAction();
+ int indentation = pdoc->GetLineIndentation(lineCurrentPos);
+ int indentationStep = (pdoc->indentInChars ? pdoc->indentInChars : pdoc->tabInChars);
+ if (indentation % indentationStep == 0) {
+ pdoc->SetLineIndentation(lineCurrentPos, indentation - indentationStep);
+ } else {
+ pdoc->SetLineIndentation(lineCurrentPos, indentation - (indentation % indentationStep));
+ }
+ SetEmptySelection(pdoc->GetLineIndentPosition(lineCurrentPos));
+ pdoc->EndUndoAction();
} else {
- pdoc->SetLineIndentation(lineCurrentPos, indentation - (indentation % indentationStep));
+ pdoc->DelCharBack(currentPos);
}
- SetEmptySelection(pdoc->GetLineIndentPosition(lineCurrentPos));
- pdoc->EndUndoAction();
- } else {
- pdoc->DelCharBack(currentPos);
}
}
} else {
diff --git a/src/Editor.h b/src/Editor.h
index 6304f078a..0e489a402 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -328,6 +328,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
void SetSelection(int currentPos_, int anchor_);
void SetSelection(int currentPos_);
void SetEmptySelection(int currentPos_);
+ bool RangeContainsProtected(int start, int end) const;
+ bool SelectionContainsProtected() const;
int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
int MovePositionTo(int newPos, bool extend=false, bool ensureVisible=true);
int MovePositionSoVisible(int pos, int moveDir);
diff --git a/src/Style.h b/src/Style.h
index 63259b1a9..6245b0b77 100644
--- a/src/Style.h
+++ b/src/Style.h
@@ -49,7 +49,7 @@ public:
void ClearTo(const Style &source);
bool EquivalentFontTo(const Style *other) const;
void Realise(Surface &surface, int zoomLevel, Style *defaultStyle = 0);
- bool IsProtected() { return !(changeable && visible);} ;
+ bool IsProtected() const { return !(changeable && visible);};
};
#endif
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 91f2d2d2f..ea1b3e955 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -139,6 +139,7 @@ void ViewStyle::Init() {
edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
edgeState = EDGE_NONE;
caretWidth = 1;
+ someStylesProtected = false;
leftMarginWidth = 1;
rightMarginWidth = 1;
@@ -197,6 +198,7 @@ void ViewStyle::Refresh(Surface &surface) {
styles[STYLE_DEFAULT].Realise(surface, zoomLevel);
maxAscent = styles[STYLE_DEFAULT].ascent;
maxDescent = styles[STYLE_DEFAULT].descent;
+ someStylesProtected = false;
for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
if (i != STYLE_DEFAULT) {
styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT]);
@@ -205,6 +207,9 @@ void ViewStyle::Refresh(Surface &surface) {
if (maxDescent < styles[i].descent)
maxDescent = styles[i].descent;
}
+ if (styles[i].IsProtected()) {
+ someStylesProtected = true;
+ }
}
lineHeight = maxAscent + maxDescent;
@@ -243,3 +248,7 @@ void ViewStyle::ClearStyles() {
void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
styles[styleIndex].fontName = fontNames.Save(name);
}
+
+bool ViewStyle::ProtectionActive() const {
+ return someStylesProtected;
+}
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 887170eaa..d43ccef67 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -78,6 +78,7 @@ public:
ColourPair edgecolour;
int edgeState;
int caretWidth;
+ bool someStylesProtected;
ViewStyle();
ViewStyle(const ViewStyle &source);
@@ -88,6 +89,7 @@ public:
void ResetDefaultStyle();
void ClearStyles();
void SetStyleFontName(int styleIndex, const char *name);
+ bool ProtectionActive() const;
};
#endif