aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2002-04-03 12:51:37 +0000
committernyamatongwe <unknown>2002-04-03 12:51:37 +0000
commit8947805be9f56db782923bc07fb948524df95030 (patch)
treea9a11313782ccf31cd3a41a64a558d20a4077f3f /src
parent570bedab6964a0fa3d2a1c74053fa7c54fa02c08 (diff)
downloadscintilla-mirror-8947805be9f56db782923bc07fb948524df95030.tar.gz
Enhancements to read-only mode to stop caret moving when typing or deleting.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx44
-rw-r--r--src/Document.h11
-rw-r--r--src/Editor.cxx25
3 files changed, 47 insertions, 33 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 3d3e5a51d..4272dda63 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -344,11 +344,11 @@ void Document::ModifiedAt(int pos) {
// SetStyleAt does not change the persistent state of a document
// Unlike Undo, Redo, and InsertStyledString, the pos argument is a cell number not a char number
-void Document::DeleteChars(int pos, int len) {
+bool Document::DeleteChars(int pos, int len) {
if (len == 0)
- return;
+ return false;
if ((pos + len) > Length())
- return;
+ return false;
if (cb.IsReadOnly() && enteredReadOnlyCount == 0) {
enteredReadOnlyCount++;
NotifyModifyAttempt();
@@ -379,9 +379,10 @@ void Document::DeleteChars(int pos, int len) {
}
enteredCount--;
}
+ return !cb.IsReadOnly();
}
-void Document::InsertStyledString(int position, char *s, int insertLength) {
+bool Document::InsertStyledString(int position, char *s, int insertLength) {
if (cb.IsReadOnly() && enteredReadOnlyCount == 0) {
enteredReadOnlyCount++;
NotifyModifyAttempt();
@@ -409,6 +410,7 @@ void Document::InsertStyledString(int position, char *s, int insertLength) {
}
enteredCount--;
}
+ return !cb.IsReadOnly();
}
int Document::Undo() {
@@ -497,29 +499,31 @@ int Document::Redo() {
return newPos;
}
-void Document::InsertChar(int pos, char ch) {
+bool Document::InsertChar(int pos, char ch) {
char chs[2];
chs[0] = ch;
chs[1] = 0;
- InsertStyledString(pos*2, chs, 2);
+ return InsertStyledString(pos*2, chs, 2);
}
// Insert a null terminated string
-void Document::InsertString(int position, const char *s) {
- InsertString(position, s, strlen(s));
+bool Document::InsertString(int position, const char *s) {
+ return InsertString(position, s, strlen(s));
}
// Insert a string with a length
-void Document::InsertString(int position, const char *s, int insertLength) {
+bool Document::InsertString(int position, const char *s, int insertLength) {
+ bool changed = false;
char *sWithStyle = new char[insertLength * 2];
if (sWithStyle) {
for (int i = 0; i < insertLength; i++) {
sWithStyle[i*2] = s[i];
sWithStyle[i*2 + 1] = 0;
}
- InsertStyledString(position*2, sWithStyle, insertLength*2);
+ changed = InsertStyledString(position*2, sWithStyle, insertLength*2);
delete []sWithStyle;
}
+ return changed;
}
void Document::ChangeChar(int pos, char ch) {
@@ -531,22 +535,26 @@ void Document::DelChar(int pos) {
DeleteChars(pos, LenChar(pos));
}
+int Document::DelCharBackMove(int pos, int len) {
+ if (DeleteChars(pos - len, len)) {
+ return pos - len;
+ } else {
+ return pos;
+ }
+}
+
int Document::DelCharBack(int pos) {
if (pos <= 0) {
return pos;
} else if (IsCrLf(pos - 2)) {
- DeleteChars(pos - 2, 2);
- return pos - 2;
+ return DelCharBackMove(pos, 2);
} else if (SC_CP_UTF8 == dbcsCodePage) {
int startChar = MovePositionOutsideChar(pos - 1, -1, false);
- DeleteChars(startChar, pos - startChar);
- return startChar;
+ return DelCharBackMove(pos, pos - startChar);
} else if (IsDBCS(pos - 1)) {
- DeleteChars(pos - 2, 2);
- return pos - 2;
+ return DelCharBackMove(pos, 2);
} else {
- DeleteChars(pos - 1, 1);
- return pos - 1;
+ return DelCharBackMove(pos, 1);
}
}
diff --git a/src/Document.h b/src/Document.h
index 941ad79cc..61fe33fce 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -132,8 +132,8 @@ public:
int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
// Gateways to modifying document
- void DeleteChars(int pos, int len);
- void InsertStyledString(int position, char *s, int insertLength);
+ bool DeleteChars(int pos, int len);
+ bool InsertStyledString(int position, char *s, int insertLength);
int Undo();
int Redo();
bool CanUndo() { return cb.CanUndo(); }
@@ -158,9 +158,9 @@ public:
void SetReadOnly(bool set) { cb.SetReadOnly(set); }
bool IsReadOnly() { return cb.IsReadOnly(); }
- void InsertChar(int pos, char ch);
- void InsertString(int position, const char *s);
- void InsertString(int position, const char *s, int insertLength);
+ bool InsertChar(int pos, char ch);
+ bool InsertString(int position, const char *s);
+ bool InsertString(int position, const char *s, int insertLength);
void ChangeChar(int pos, char ch);
void DelChar(int pos);
int DelCharBack(int pos);
@@ -233,6 +233,7 @@ private:
void NotifySavePoint(bool atSavePoint);
void NotifyModified(DocModification mh);
+ int DelCharBackMove(int pos, int len);
int IndentSize() { return indentInChars ? indentInChars : tabInChars; }
};
diff --git a/src/Editor.cxx b/src/Editor.cxx
index fd8a2d719..d66b49238 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -2220,8 +2220,9 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
}
}
}
- pdoc->InsertString(currentPos, s, len);
- SetEmptySelection(currentPos + len);
+ if (pdoc->InsertString(currentPos, s, len)) {
+ SetEmptySelection(currentPos + len);
+ }
EnsureCaretVisible();
// Avoid blinking during rapid typing:
ShowCaretAtCurrentPosition();
@@ -3456,9 +3457,10 @@ void Editor::DropAt(int position, const char *value, bool moving, bool rectangul
SetSelection(position, position);
} else {
position = MovePositionOutsideChar(position, currentPos - position);
- pdoc->InsertString(position, value);
+ if (pdoc->InsertString(position, value)) {
+ SetSelection(position + strlen(value), position);
+ }
pdoc->EndUndoAction();
- SetSelection(position + strlen(value), position);
}
} else if (inDragDrop) {
SetSelection(position, position);
@@ -3743,17 +3745,20 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) {
if (selStart < selEnd) {
if (drag.len) {
if (ctrl) {
- pdoc->InsertString(newPos, drag.s, drag.len);
- SetSelection(newPos, newPos + drag.len);
+ if (pdoc->InsertString(newPos, drag.s, drag.len)) {
+ SetSelection(newPos, newPos + drag.len);
+ }
} else if (newPos < selStart) {
pdoc->DeleteChars(selStart, drag.len);
- pdoc->InsertString(newPos, drag.s, drag.len);
- SetSelection(newPos, newPos + drag.len);
+ if (pdoc->InsertString(newPos, drag.s, drag.len)) {
+ SetSelection(newPos, newPos + drag.len);
+ }
} else if (newPos > selEnd) {
pdoc->DeleteChars(selStart, drag.len);
newPos -= drag.len;
- pdoc->InsertString(newPos, drag.s, drag.len);
- SetSelection(newPos, newPos + drag.len);
+ if (pdoc->InsertString(newPos, drag.s, drag.len)) {
+ SetSelection(newPos, newPos + drag.len);
+ }
} else {
SetEmptySelection(newPos);
}