Skip to content

Commit

Permalink
* Support block caret in overtype mode (revert commit 6357856). https…
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Feb 5, 2019
1 parent 03d9fbf commit bd3a266
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 22 deletions.
4 changes: 3 additions & 1 deletion scintilla/include/Scintilla.h
Expand Up @@ -841,7 +841,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
Expand Down
4 changes: 3 additions & 1 deletion scintilla/include/Scintilla.iface
Expand Up @@ -2199,7 +2199,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,)
Expand Down
11 changes: 6 additions & 5 deletions scintilla/src/EditView.cxx
Expand Up @@ -1422,7 +1422,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
Expand Down Expand Up @@ -1453,7 +1453,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;
Expand All @@ -1477,16 +1477,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]))) {
Expand Down
4 changes: 2 additions & 2 deletions scintilla/src/Editor.cxx
Expand Up @@ -1358,7 +1358,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(SelectionRange range, con
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);
}
Expand Down Expand Up @@ -7336,7 +7336,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 */
Expand Down
13 changes: 13 additions & 0 deletions scintilla/src/ViewStyle.cxx
Expand Up @@ -567,6 +567,19 @@ bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) noexcept {
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;
}

bool ViewStyle::ZoomIn() noexcept {
if (zoomLevel < SC_MAX_ZOOM_LEVEL) {
int level = zoomLevel;
Expand Down
4 changes: 4 additions & 0 deletions scintilla/src/ViewStyle.h
Expand Up @@ -215,6 +215,10 @@ class ViewStyle {

bool WhiteSpaceVisible(bool inIndent) const noexcept;

enum class CaretShape { invisible, line, block, bar };
bool IsBlockCaretStyle() const noexcept;
CaretShape CaretShapeForMode(bool inOverstrike) const noexcept;

bool ZoomIn() noexcept;
bool ZoomOut() noexcept;

Expand Down
12 changes: 9 additions & 3 deletions src/Notepad2.c
Expand Up @@ -288,6 +288,7 @@ static int iAlignMode = 0;
int iMatchesCount = 0;
extern int iFontQuality;
extern int iCaretStyle;
extern int iOvrCaretStyle;
extern int iCaretBlinkPeriod;

static BOOL fIsElevated = FALSE;
Expand Down Expand Up @@ -2328,6 +2329,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) {
CheckCmd(hmenu, IDM_VIEW_WORDWRAP, fWordWrap);
i = IDM_VIEW_FONTQUALITY_DEFAULT + iFontQuality;
CheckMenuRadioItem(hmenu, IDM_VIEW_FONTQUALITY_DEFAULT, IDM_VIEW_FONTQUALITY_CLEARTYPE, i, MF_BYCOMMAND);
CheckCmd(hmenu, IDM_VIEW_CARET_STYLE_BLOCK_OVR, iOvrCaretStyle);
i = IDM_VIEW_CARET_STYLE_BLOCK + iCaretStyle;
CheckMenuRadioItem(hmenu, IDM_VIEW_CARET_STYLE_BLOCK, IDM_VIEW_CARET_STYLE_WIDTH3, i, MF_BYCOMMAND);
CheckCmd(hmenu, IDM_VIEW_CARET_STYLE_NOBLINK, iCaretBlinkPeriod == 0);
Expand Down Expand Up @@ -4120,7 +4122,10 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
SendMessage(hwndEdit, SCI_SETFONTQUALITY, iFontQuality, 0);
break;

case IDM_VIEW_CARET_STYLE_BLOCK_BOTH:
case IDM_VIEW_CARET_STYLE_BLOCK_OVR:
iOvrCaretStyle = !iOvrCaretStyle;
Style_UpdateCaret(hwndEdit);
break;
case IDM_VIEW_CARET_STYLE_BLOCK:
case IDM_VIEW_CARET_STYLE_WIDTH1:
case IDM_VIEW_CARET_STYLE_WIDTH2:
Expand Down Expand Up @@ -5311,7 +5316,8 @@ void LoadSettings(void) {
iFontQuality = clamp_i(iValue, SC_EFF_QUALITY_DEFAULT, SC_EFF_QUALITY_LCD_OPTIMIZED);

iValue = IniSectionGetInt(pIniSection, L"CaretStyle", 1);
iCaretStyle = clamp_i(iValue, -1, 3);
iOvrCaretStyle = clamp_i(iValue / 10, 0, 1);
iCaretStyle = clamp_i(iValue % 10, 0, 3);
iCaretBlinkPeriod = IniSectionGetInt(pIniSection, L"CaretBlinkPeriod", -1);

// Korean IME use inline mode (and block caret in inline mode) by default
Expand Down Expand Up @@ -5563,7 +5569,7 @@ void SaveSettings(BOOL bSaveSettingsNow) {
IniSectionSetIntEx(pIniSection, L"RenderingTechnology", iRenderingTechnology, (IsVistaAndAbove()? SC_TECHNOLOGY_DIRECTWRITE : SC_TECHNOLOGY_DEFAULT));
IniSectionSetIntEx(pIniSection, L"Bidirectional", iBidirectional, SC_BIDIRECTIONAL_DISABLED);
IniSectionSetIntEx(pIniSection, L"FontQuality", iFontQuality, SC_EFF_QUALITY_LCD_OPTIMIZED);
IniSectionSetIntEx(pIniSection, L"CaretStyle", iCaretStyle, 1);
IniSectionSetIntEx(pIniSection, L"CaretStyle", iCaretStyle + iOvrCaretStyle*10, 1);
IniSectionSetIntEx(pIniSection, L"CaretBlinkPeriod", iCaretBlinkPeriod, -1);
IniSectionSetBool(pIniSection, L"UseInlineIME", bUseInlineIME); // keep result of auto detection
IniSectionSetBoolEx(pIniSection, L"InlineIMEUseBlockCaret", bInlineIMEUseBlockCaret, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/Notepad2.rc
Expand Up @@ -372,9 +372,9 @@ BEGIN
END
POPUP "Caret Style"
BEGIN
MENUITEM "Block (Both Mode)", IDM_VIEW_CARET_STYLE_BLOCK_BOTH
MENUITEM "Block (INS Mode)", IDM_VIEW_CARET_STYLE_BLOCK
MENUITEM "Block (OVR Mode)", IDM_VIEW_CARET_STYLE_BLOCK_OVR
MENUITEM SEPARATOR
MENUITEM "Block (INS Mode)", IDM_VIEW_CARET_STYLE_BLOCK
MENUITEM "Width 1", IDM_VIEW_CARET_STYLE_WIDTH1
MENUITEM "Width 2", IDM_VIEW_CARET_STYLE_WIDTH2
MENUITEM "Width 3", IDM_VIEW_CARET_STYLE_WIDTH3
Expand Down
11 changes: 6 additions & 5 deletions src/Styles.c
Expand Up @@ -255,7 +255,8 @@ static UINT fStylesModified = STYLESMODIFIED_NONE;
static BOOL fWarnedNoIniFile = FALSE;
static int iBaseFontSize = 11*SC_FONT_SIZE_MULTIPLIER; // 11 pt in lexDefault
int iFontQuality = SC_EFF_QUALITY_LCD_OPTIMIZED;
int iCaretStyle = 1; // width 1, 0 for block, -1 for always block
int iCaretStyle = 1; // width 1, 0 for block
int iOvrCaretStyle = 0; // 0 for bar, 1 for block
int iCaretBlinkPeriod = -1; // system default, 0 for noblink
static int iDefaultLexer;
static BOOL bAutoSelect;
Expand Down Expand Up @@ -700,10 +701,10 @@ void Style_OnDPIChanged(HWND hwnd) {

void Style_UpdateCaret(HWND hwnd) {
// caret style and width
if (iCaretStyle <= 0) {
SendMessage(hwnd, SCI_SETCARETSTYLE, ((iCaretStyle == 0) ? CARETSTYLE_BLOCK : CARETSTYLE_BLOCK_ALWAYS), 0);
} else {
SendMessage(hwnd, SCI_SETCARETSTYLE, CARETSTYLE_LINE, 0);
const int style = (iCaretStyle ? CARETSTYLE_LINE : CARETSTYLE_BLOCK)
| (iOvrCaretStyle ? CARETSTYLE_OVERSTRIKE_BLOCK : CARETSTYLE_OVERSTRIKE_BAR);
SendMessage(hwnd, SCI_SETCARETSTYLE, style, 0);
if (iCaretStyle != 0) {
SendMessage(hwnd, SCI_SETCARETWIDTH, iCaretStyle, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/resource.h
Expand Up @@ -610,7 +610,7 @@
#define IDM_VIEW_FONTQUALITY_NONE 40066
#define IDM_VIEW_FONTQUALITY_STANDARD 40067
#define IDM_VIEW_FONTQUALITY_CLEARTYPE 40068
#define IDM_VIEW_CARET_STYLE_BLOCK_BOTH 40069
#define IDM_VIEW_CARET_STYLE_BLOCK_OVR 40069
#define IDM_VIEW_CARET_STYLE_BLOCK 40070
#define IDM_VIEW_CARET_STYLE_WIDTH1 40071
#define IDM_VIEW_CARET_STYLE_WIDTH2 40072
Expand Down
4 changes: 2 additions & 2 deletions version.txt
Expand Up @@ -5,12 +5,12 @@ git clone https://github.com/XhmikosR/notepad2-mod.git
Scintilla
hg clone http://hg.code.sf.net/p/scintilla/code scintilla
4.1.3
2019-02-02 7245:aba09a1c7c63
2019-02-05 7248:06b6a93d8e3f

SciTE
hg clone http://hg.code.sf.net/p/scintilla/scite
4.1.3
2019-02-02 5122:d75981e484ee
2019-02-05 5123:ce6b6778a246

Notepad++
https://github.com/notepad-plus-plus/notepad-plus-plus.git
Expand Down

0 comments on commit bd3a266

Please sign in to comment.