aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaDoc.html8
-rw-r--r--doc/ScintillaHistory.html2
-rw-r--r--include/Scintilla.h4
-rw-r--r--include/Scintilla.iface4
-rw-r--r--src/EditView.cxx11
-rw-r--r--src/Editor.cxx4
-rw-r--r--src/ViewStyle.cxx13
-rw-r--r--src/ViewStyle.h4
8 files changed, 36 insertions, 14 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 81f2ef551..56f7822ab 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -3210,10 +3210,10 @@ struct Sci_TextToFind {
<p><b id="SCI_SETCARETSTYLE">SCI_SETCARETSTYLE(int caretStyle)</b><br />
<b id="SCI_GETCARETSTYLE">SCI_GETCARETSTYLE &rarr; int</b><br />
The style of the caret can be set with <code>SCI_SETCARETSTYLE</code> to be a line caret
- (CARETSTYLE_LINE=1, insert mode), a block caret (CARETSTYLE_BLOCK=2, insert mode),
- a block caret in both insert and overtype mode (CARETSTYLE_BLOCK_ALWAYS=3) or to not draw at all
- (CARETSTYLE_INVISIBLE=0, insert mode). The default value for insert mode is the line caret (CARETSTYLE_LINE=1),
- for overtype mode is the bar caret.
+ (CARETSTYLE_LINE=1) or a block caret (CARETSTYLE_BLOCK=2) for insert mode combined with
+ a bar caret (CARETSTYLE_OVERSTRIKE_BAR=0) or a block caret (CARETSTYLE_OVERSTRIKE_BLOCK=16) for overtype mode,
+ or to not draw at all (CARETSTYLE_INVISIBLE=0). The default value for insert mode is the line caret (CARETSTYLE_LINE=1),
+ for overtype mode is the bar caret (CARETSTYLE_OVERSTRIKE_BAR=0).
You can determine the current caret style setting using <code>SCI_GETCARETSTYLE</code>.</p>
<p>The block caret draws most combining and multibyte character sequences successfully,
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 6156a68a4..d34f4bf2e 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -554,7 +554,7 @@
<a href="https://sourceforge.net/p/scintilla/bugs/1548/">Bug #1548</a>.
</li>
<li>
- Block caret in both insert and overtype mode SCI_SETCARETSTYLE(CARETSTYLE_BLOCK_ALWAYS).
+ Block caret in overtype mode SCI_SETCARETSTYLE(caretStyle | CARETSTYLE_OVERSTRIKE_BLOCK).
<a href="https://sourceforge.net/p/scintilla/feature-requests/1217/">Feature #1217</a>.
</li>
<li>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 9a7ddb1b3..cb3259842 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -829,7 +829,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define CARETSTYLE_INVISIBLE 0
#define CARETSTYLE_LINE 1
#define CARETSTYLE_BLOCK 2
-#define CARETSTYLE_BLOCK_ALWAYS 3
+#define CARETSTYLE_OVERSTRIKE_BAR 0
+#define CARETSTYLE_OVERSTRIKE_BLOCK 16
+#define CARETSTYLE_INS_MASK 0xF
#define SCI_SETCARETSTYLE 2512
#define SCI_GETCARETSTYLE 2513
#define SCI_SETINDICATORCURRENT 2500
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index f0099d901..8efe13647 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2178,7 +2178,9 @@ enu CaretStyle=CARETSTYLE_
val CARETSTYLE_INVISIBLE=0
val CARETSTYLE_LINE=1
val CARETSTYLE_BLOCK=2
-val CARETSTYLE_BLOCK_ALWAYS=3
+val CARETSTYLE_OVERSTRIKE_BAR=0
+val CARETSTYLE_OVERSTRIKE_BLOCK=16
+val CARETSTYLE_INS_MASK=0xF
# Set the style of the caret to be drawn.
set void SetCaretStyle=2512(int caretStyle,)
diff --git a/src/EditView.cxx b/src/EditView.cxx
index 8eaaee32c..31885ba62 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -1331,7 +1331,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt
for (size_t r = 0; (r<model.sel.Count()) || drawDrag; r++) {
const bool mainCaret = r == model.sel.Main();
SelectionPosition posCaret = (drawDrag ? model.posDrag : model.sel.Range(r).caret);
- if ((vsDraw.caretStyle == CARETSTYLE_BLOCK || vsDraw.caretStyle == CARETSTYLE_BLOCK_ALWAYS) && !drawDrag && posCaret > model.sel.Range(r).anchor) {
+ if ((vsDraw.IsBlockCaretStyle() || imeCaretBlockOverride) && !drawDrag && posCaret > model.sel.Range(r).anchor) {
if (posCaret.VirtualSpace() > 0)
posCaret.SetVirtualSpace(posCaret.VirtualSpace() - 1);
else
@@ -1350,7 +1350,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt
const bool caretBlinkState = (model.caret.active && model.caret.on) || (!additionalCaretsBlink && !mainCaret);
const bool caretVisibleState = additionalCaretsVisible || mainCaret;
if ((xposCaret >= 0) && (vsDraw.caretWidth > 0) && (vsDraw.caretStyle != CARETSTYLE_INVISIBLE) &&
- ((model.posDrag.IsValid()) || (caretBlinkState && caretVisibleState))) {
+ (drawDrag || (caretBlinkState && caretVisibleState))) {
bool caretAtEOF = false;
bool caretAtEOL = false;
bool drawBlockCaret = false;
@@ -1374,16 +1374,17 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt
if (xposCaret > 0)
caretWidthOffset = 0.51f; // Move back so overlaps both character cells.
xposCaret += xStart;
- if (model.posDrag.IsValid()) {
+ const ViewStyle::CaretShape caretShape = drawDrag ? ViewStyle::CaretShape::line : vsDraw.CaretShapeForMode(model.inOverstrike);
+ if (drawDrag) {
/* Dragging text, use a line caret */
rcCaret.left = round(xposCaret - caretWidthOffset);
rcCaret.right = rcCaret.left + vsDraw.caretWidth;
- } else if ((model.inOverstrike && vsDraw.caretStyle != CARETSTYLE_BLOCK_ALWAYS) && drawOverstrikeCaret) {
+ } else if ((caretShape == ViewStyle::CaretShape::bar) && drawOverstrikeCaret) {
/* Overstrike (insert mode), use a modified bar caret */
rcCaret.top = rcCaret.bottom - 2;
rcCaret.left = xposCaret + 1;
rcCaret.right = rcCaret.left + widthOverstrikeCaret - 1;
- } else if ((vsDraw.caretStyle == CARETSTYLE_BLOCK || vsDraw.caretStyle == CARETSTYLE_BLOCK_ALWAYS) || imeCaretBlockOverride) {
+ } else if ((caretShape == ViewStyle::CaretShape::block) || imeCaretBlockOverride) {
/* Block caret */
rcCaret.left = xposCaret;
if (!caretAtEOL && !caretAtEOF && (ll->chars[offset] != '\t') && !(IsControlCharacter(ll->chars[offset]))) {
diff --git a/src/Editor.cxx b/src/Editor.cxx
index f48ba333b..e6a1637f9 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1351,7 +1351,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
newXY.xOffset = static_cast<int>(pt.x + xOffset - rcClient.left) - 2;
} else if (pt.x + xOffset >= rcClient.right + newXY.xOffset) {
newXY.xOffset = static_cast<int>(pt.x + xOffset - rcClient.right) + 2;
- if ((vs.caretStyle == CARETSTYLE_BLOCK || vs.caretStyle == CARETSTYLE_BLOCK_ALWAYS) || view.imeCaretBlockOverride) {
+ if (vs.IsBlockCaretStyle() || view.imeCaretBlockOverride) {
// Ensure we can see a good portion of the block caret
newXY.xOffset += static_cast<int>(vs.aveCharWidth);
}
@@ -7277,7 +7277,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return vs.caretcolour.AsInteger();
case SCI_SETCARETSTYLE:
- if (wParam <= CARETSTYLE_BLOCK_ALWAYS)
+ if (wParam <= (CARETSTYLE_BLOCK | CARETSTYLE_OVERSTRIKE_BLOCK))
vs.caretStyle = static_cast<int>(wParam);
else
/* Default to the line caret */
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 016855615..54f20de4b 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -571,6 +571,19 @@ bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) {
return changed;
}
+bool ViewStyle::IsBlockCaretStyle() const noexcept {
+ return (caretStyle == CARETSTYLE_BLOCK) || (caretStyle & CARETSTYLE_OVERSTRIKE_BLOCK) != 0;
+}
+
+ViewStyle::CaretShape ViewStyle::CaretShapeForMode(bool inOverstrike) const noexcept {
+ if (inOverstrike) {
+ return (caretStyle & CARETSTYLE_OVERSTRIKE_BLOCK) ? CaretShape::block : CaretShape::bar;
+ }
+
+ const int caret = caretStyle & CARETSTYLE_INS_MASK;
+ return (caret <= CARETSTYLE_BLOCK) ? static_cast<CaretShape>(caret) : CaretShape::line;
+}
+
void ViewStyle::AllocStyles(size_t sizeNew) {
size_t i=styles.size();
styles.resize(sizeNew);
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 800d8cb67..4ef82c393 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -212,6 +212,10 @@ public:
bool WhiteSpaceVisible(bool inIndent) const;
+ enum class CaretShape { invisible, line, block, bar };
+ bool IsBlockCaretStyle() const noexcept;
+ CaretShape CaretShapeForMode(bool inOverstrike) const noexcept;
+
private:
void AllocStyles(size_t sizeNew);
void CreateAndAddFont(const FontSpecification &fs);