Update Scintilla to version 3.6.3

Includes improvements for Lua 5.3 and Perl 5.22.
This commit is contained in:
Colomban Wendling 2016-01-18 04:22:26 +01:00
parent f3a5dd609a
commit 99938dd821
32 changed files with 531 additions and 264 deletions

View File

@ -296,8 +296,6 @@ private:
static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis); static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis);
void MoveImeCarets(int pos); void MoveImeCarets(int pos);
void DrawImeIndicator(int indicator, int len); void DrawImeIndicator(int indicator, int len);
static void GetImeUnderlines(PangoAttrList *attrs, bool *normalInput);
static void GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput);
void SetCandidateWindowPos(); void SetCandidateWindowPos();
static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*); static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*);
@ -2328,24 +2326,28 @@ void ScintillaGTK::DrawImeIndicator(int indicator, int len) {
} }
} }
void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) { static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str) {
// Whether single underlines attribute is or not // Map input style to scintilla ime indicator.
// attr position is counted by the number of UTF-8 bytes // Attrs position points between UTF-8 bytes.
// Indicator index to be returned is character based though.
glong charactersLen = g_utf8_strlen(u8Str, strlen(u8Str));
std::vector<int> indicator(charactersLen, SC_INDICATOR_UNKNOWN);
PangoAttrIterator *iterunderline = pango_attr_list_get_iterator(attrs); PangoAttrIterator *iterunderline = pango_attr_list_get_iterator(attrs);
if (iterunderline) { if (iterunderline) {
do { do {
PangoAttribute *attrunderline = pango_attr_iterator_get(iterunderline, PANGO_ATTR_UNDERLINE); PangoAttribute *attrunderline = pango_attr_iterator_get(iterunderline, PANGO_ATTR_UNDERLINE);
if (attrunderline) { if (attrunderline) {
glong start = attrunderline->start_index; glong start = g_utf8_strlen(u8Str, attrunderline->start_index);
glong end = attrunderline->end_index; glong end = g_utf8_strlen(u8Str, attrunderline->end_index);
PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value; PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value;
for (glong i=start; i < end; ++i) { for (glong i=start; i < end; ++i) {
switch (uline) { switch (uline) {
case PANGO_UNDERLINE_NONE: case PANGO_UNDERLINE_NONE:
normalInput[i] = false; indicator[i] = SC_INDICATOR_UNKNOWN;
break; break;
case PANGO_UNDERLINE_SINGLE: // normal input case PANGO_UNDERLINE_SINGLE: // normal input
normalInput[i] = true; indicator[i] = SC_INDICATOR_INPUT;
break; break;
case PANGO_UNDERLINE_DOUBLE: case PANGO_UNDERLINE_DOUBLE:
case PANGO_UNDERLINE_LOW: case PANGO_UNDERLINE_LOW:
@ -2357,25 +2359,22 @@ void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) {
} while (pango_attr_iterator_next(iterunderline)); } while (pango_attr_iterator_next(iterunderline));
pango_attr_iterator_destroy(iterunderline); pango_attr_iterator_destroy(iterunderline);
} }
}
void ScintillaGTK::GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput) {
// Whether background color attribue is or not
// attr position is measured in UTF-8 bytes
PangoAttrIterator *itercolor = pango_attr_list_get_iterator(attrs); PangoAttrIterator *itercolor = pango_attr_list_get_iterator(attrs);
if (itercolor) { if (itercolor) {
do { do {
PangoAttribute *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND); PangoAttribute *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND);
if (backcolor) { if (backcolor) {
glong start = backcolor->start_index; glong start = g_utf8_strlen(u8Str, backcolor->start_index);
glong end = backcolor->end_index; glong end = g_utf8_strlen(u8Str, backcolor->end_index);
for (glong i=start; i < end; ++i) { for (glong i=start; i < end; ++i) {
targetInput[i] = true; // target converted indicator[i] = SC_INDICATOR_TARGET; // target converted
} }
} }
} while (pango_attr_iterator_next(itercolor)); } while (pango_attr_iterator_next(itercolor));
pango_attr_iterator_destroy(itercolor); pango_attr_iterator_destroy(itercolor);
} }
return indicator;
} }
void ScintillaGTK::SetCandidateWindowPos() { void ScintillaGTK::SetCandidateWindowPos() {
@ -2401,23 +2400,13 @@ void ScintillaGTK::CommitThis(char *commitStr) {
glong uniStrLen = 0; glong uniStrLen = 0;
gunichar *uniStr = g_utf8_to_ucs4_fast(commitStr, strlen(commitStr), &uniStrLen); gunichar *uniStr = g_utf8_to_ucs4_fast(commitStr, strlen(commitStr), &uniStrLen);
for (glong i = 0; i < uniStrLen; i++) { for (glong i = 0; i < uniStrLen; i++) {
gchar u8Char[UTF8MaxBytes+2] = {0};
gint u8CharLen = g_unichar_to_utf8(uniStr[i], u8Char);
std::string docChar = u8Char;
if (!IsUnicodeMode())
docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true);
gunichar uniChar[1] = {0}; AddCharUTF(docChar.c_str(), docChar.size());
uniChar[0] = uniStr[i];
glong oneCharLen = 0;
gchar *oneChar = g_ucs4_to_utf8(uniChar, 1, NULL, &oneCharLen, NULL);
if (IsUnicodeMode()) {
// Do nothing ;
} else {
std::string oneCharSTD = ConvertText(oneChar, oneCharLen, charSetSource, "UTF-8", true);
oneCharLen = oneCharSTD.copy(oneChar,oneCharSTD.length(), 0);
oneChar[oneCharLen] = '\0';
}
AddCharUTF(oneChar, oneCharLen);
g_free(oneChar);
} }
g_free(uniStr); g_free(uniStr);
ShowCaretAtCurrentPosition(); ShowCaretAtCurrentPosition();
@ -2434,6 +2423,11 @@ void ScintillaGTK::PreeditChangedInlineThis() {
// Copy & paste by johnsonj with a lot of helps of Neil // Copy & paste by johnsonj with a lot of helps of Neil
// Great thanks for my foreruners, jiniya and BLUEnLIVE // Great thanks for my foreruners, jiniya and BLUEnLIVE
try { try {
if (pdoc->IsReadOnly() || SelectionContainsProtected()) {
gtk_im_context_reset(im_context);
return;
}
view.imeCaretBlockOverride = false; // If backspace. view.imeCaretBlockOverride = false; // If backspace.
if (pdoc->TentativeActive()) { if (pdoc->TentativeActive()) {
@ -2461,64 +2455,38 @@ void ScintillaGTK::PreeditChangedInlineThis() {
pdoc->TentativeStart(); // TentativeActive() from now on pdoc->TentativeStart(); // TentativeActive() from now on
// Get preedit string attribues // Get preedit string attribues
bool normalInput[maxLenInputIME*3+1] = {false}; std::vector<int> indicator = MapImeIndicators(preeditStr.attrs, preeditStr.str);
bool targetInput[maxLenInputIME*3+1] = {false};
GetImeUnderlines(preeditStr.attrs, normalInput);
GetImeBackgrounds(preeditStr.attrs, targetInput);
// Display preedit characters, one by one // Display preedit characters, one by one
glong imeCharPos[maxLenInputIME+1] = { 0 }; glong imeCharPos[maxLenInputIME+1] = { 0 };
glong attrPos = -1; // Start at -1 to designate the last byte of one character.
glong charWidth = 0; glong charWidth = 0;
bool tmpRecordingMacro = recordingMacro; bool tmpRecordingMacro = recordingMacro;
recordingMacro = false; recordingMacro = false;
for (glong i = 0; i < preeditStr.uniStrLen; i++) { for (glong i = 0; i < preeditStr.uniStrLen; i++) {
gchar u8Char[UTF8MaxBytes+2] = {0};
gint u8CharLen = g_unichar_to_utf8(preeditStr.uniStr[i], u8Char);
std::string docChar = u8Char;
if (!IsUnicodeMode())
docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true);
gunichar uniChar[1] = {0}; AddCharUTF(docChar.c_str(), docChar.size());
uniChar[0] = preeditStr.uniStr[i];
glong oneCharLen = 0;
gchar *oneChar = g_ucs4_to_utf8(uniChar, 1, NULL, &oneCharLen, NULL);
// Record attribute positions in UTF-8 bytes
attrPos += oneCharLen;
if (IsUnicodeMode()) {
// Do nothing
} else {
std::string oneCharSTD = ConvertText(oneChar, oneCharLen, charSetSource, "UTF-8", true);
oneCharLen = oneCharSTD.copy(oneChar,oneCharSTD.length(), 0);
oneChar[oneCharLen] = '\0';
}
// Record character positions in UTF-8 or DBCS bytes
charWidth += oneCharLen;
imeCharPos[i+1] = charWidth;
// Display one character
AddCharUTF(oneChar, oneCharLen);
// Draw an indicator on the character, // Draw an indicator on the character,
// Overlapping allowed DrawImeIndicator(indicator[i], docChar.size());
if (normalInput[attrPos]) {
DrawImeIndicator(SC_INDICATOR_INPUT, oneCharLen); // Record character positions in UTF-8 or DBCS bytes
} charWidth += docChar.size();
if (targetInput[attrPos]) { imeCharPos[i+1] = charWidth;
DrawImeIndicator(SC_INDICATOR_TARGET, oneCharLen);
}
g_free(oneChar);
} }
recordingMacro = tmpRecordingMacro; recordingMacro = tmpRecordingMacro;
// Move caret to ime cursor position. // Move caret to ime cursor position.
if (KoreanIME()) { MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen]) + imeCharPos[preeditStr.cursor_pos]);
view.imeCaretBlockOverride = true;
MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen]));
} else { if (KoreanIME()) {
MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen]) + imeCharPos[preeditStr.cursor_pos]); MoveImeCarets( - imeCharPos[1]); // always 2 bytes for DBCS or 3 bytes for UTF8.
view.imeCaretBlockOverride = true;
} }
EnsureCaretVisible(); EnsureCaretVisible();
@ -3077,28 +3045,34 @@ sptr_t ScintillaGTK::DirectFunction(
return reinterpret_cast<ScintillaGTK *>(ptr)->WndProc(iMessage, wParam, lParam); return reinterpret_cast<ScintillaGTK *>(ptr)->WndProc(iMessage, wParam, lParam);
} }
/* legacy name for scintilla_object_send_message */
GEANY_API_SYMBOL GEANY_API_SYMBOL
sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin); ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin);
return psci->WndProc(iMessage, wParam, lParam); return psci->WndProc(iMessage, wParam, lParam);
} }
sptr_t scintilla_object_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return scintilla_send_message(sci, iMessage, wParam, lParam);
}
static void scintilla_class_init(ScintillaClass *klass); static void scintilla_class_init(ScintillaClass *klass);
static void scintilla_init(ScintillaObject *sci); static void scintilla_init(ScintillaObject *sci);
extern void Platform_Initialise(); extern void Platform_Initialise();
extern void Platform_Finalise(); extern void Platform_Finalise();
/* legacy name for scintilla_object_get_type */
GEANY_API_SYMBOL GEANY_API_SYMBOL
GType scintilla_get_type() { GType scintilla_get_type() {
static GType scintilla_type = 0; static GType scintilla_type = 0;
try { try {
if (!scintilla_type) { if (!scintilla_type) {
scintilla_type = g_type_from_name("Scintilla"); scintilla_type = g_type_from_name("ScintillaObject");
if (!scintilla_type) { if (!scintilla_type) {
static GTypeInfo scintilla_info = { static GTypeInfo scintilla_info = {
(guint16) sizeof (ScintillaClass), (guint16) sizeof (ScintillaObjectClass),
NULL, //(GBaseInitFunc) NULL, //(GBaseInitFunc)
NULL, //(GBaseFinalizeFunc) NULL, //(GBaseFinalizeFunc)
(GClassInitFunc) scintilla_class_init, (GClassInitFunc) scintilla_class_init,
@ -3109,9 +3083,8 @@ GType scintilla_get_type() {
(GInstanceInitFunc) scintilla_init, (GInstanceInitFunc) scintilla_init,
NULL //(GTypeValueTable*) NULL //(GTypeValueTable*)
}; };
scintilla_type = g_type_register_static( scintilla_type = g_type_register_static(
GTK_TYPE_CONTAINER, "Scintilla", &scintilla_info, (GTypeFlags) 0); GTK_TYPE_CONTAINER, "ScintillaObject", &scintilla_info, (GTypeFlags) 0);
} }
} }
@ -3120,6 +3093,10 @@ GType scintilla_get_type() {
return scintilla_type; return scintilla_type;
} }
GType scintilla_object_get_type() {
return scintilla_get_type();
}
void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class) { void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class) {
Platform_Initialise(); Platform_Initialise();
#ifdef SCI_LEXER #ifdef SCI_LEXER
@ -3135,8 +3112,8 @@ void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_
// of the signal handlers here (those that currently attached to wDraw // of the signal handlers here (those that currently attached to wDraw
// in Initialise() may require coordinate translation?) // in Initialise() may require coordinate translation?)
object_class->finalize = Destroy;
object_class->dispose = Dispose; object_class->dispose = Dispose;
object_class->finalize = Destroy;
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
widget_class->get_preferred_width = GetPreferredWidth; widget_class->get_preferred_width = GetPreferredWidth;
widget_class->get_preferred_height = GetPreferredHeight; widget_class->get_preferred_height = GetPreferredHeight;
@ -3224,6 +3201,7 @@ static void scintilla_init(ScintillaObject *sci) {
} }
} }
/* legacy name for scintilla_object_new */
GEANY_API_SYMBOL GEANY_API_SYMBOL
GtkWidget* scintilla_new() { GtkWidget* scintilla_new() {
GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL)); GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL));
@ -3232,6 +3210,10 @@ GtkWidget* scintilla_new() {
return widget; return widget;
} }
GtkWidget *scintilla_object_new() {
return scintilla_new();
}
void scintilla_set_id(ScintillaObject *sci, uptr_t id) { void scintilla_set_id(ScintillaObject *sci, uptr_t id) {
ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin); ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin);
psci->ctrlID = id; psci->ctrlID = id;

View File

@ -506,6 +506,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_WORDSTARTPOSITION 2266 #define SCI_WORDSTARTPOSITION 2266
#define SCI_WORDENDPOSITION 2267 #define SCI_WORDENDPOSITION 2267
#define SCI_ISRANGEWORD 2691 #define SCI_ISRANGEWORD 2691
#define SC_IDLESTYLING_NONE 0
#define SC_IDLESTYLING_TOVISIBLE 1
#define SC_IDLESTYLING_AFTERVISIBLE 2
#define SC_IDLESTYLING_ALL 3
#define SCI_SETIDLESTYLING 2692
#define SCI_GETIDLESTYLING 2693
#define SC_WRAP_NONE 0 #define SC_WRAP_NONE 0
#define SC_WRAP_WORD 1 #define SC_WRAP_WORD 1
#define SC_WRAP_CHAR 2 #define SC_WRAP_CHAR 2

View File

@ -249,7 +249,7 @@ enu IMEInteraction=SC_IME_
val SC_IME_WINDOWED=0 val SC_IME_WINDOWED=0
val SC_IME_INLINE=1 val SC_IME_INLINE=1
# Is the IME displayed in a winow or inline? # Is the IME displayed in a window or inline?
get int GetIMEInteraction=2678(,) get int GetIMEInteraction=2678(,)
# Choose to display the the IME in a winow or inline. # Choose to display the the IME in a winow or inline.
@ -1260,6 +1260,18 @@ fun int WordEndPosition=2267(position pos, bool onlyWordCharacters)
# Is the range start..end considered a word? # Is the range start..end considered a word?
fun bool IsRangeWord=2691(position start, position end) fun bool IsRangeWord=2691(position start, position end)
enu IdleStyling=SC_IDLESTYLING_
val SC_IDLESTYLING_NONE=0
val SC_IDLESTYLING_TOVISIBLE=1
val SC_IDLESTYLING_AFTERVISIBLE=2
val SC_IDLESTYLING_ALL=3
# Sets limits to idle styling.
set void SetIdleStyling=2692(int idleStyling,)
# Retrieve the limits to idle styling.
get int GetIdleStyling=2693(,)
enu Wrap=SC_WRAP_ enu Wrap=SC_WRAP_
val SC_WRAP_NONE=0 val SC_WRAP_NONE=0
val SC_WRAP_WORD=1 val SC_WRAP_WORD=1
@ -1408,7 +1420,7 @@ val SC_MULTIPASTE_EACH=1
# Change the effect of pasting when there are multiple selections. # Change the effect of pasting when there are multiple selections.
set void SetMultiPaste=2614(int multiPaste,) set void SetMultiPaste=2614(int multiPaste,)
# Retrieve the effect of pasting when there are multiple selections.. # Retrieve the effect of pasting when there are multiple selections.
get int GetMultiPaste=2615(,) get int GetMultiPaste=2615(,)
# Retrieve the value of a tag from a regular expression search. # Retrieve the value of a tag from a regular expression search.
@ -1977,7 +1989,7 @@ val SC_MULTIAUTOC_EACH=1
# Change the effect of autocompleting when there are multiple selections. # Change the effect of autocompleting when there are multiple selections.
set void AutoCSetMulti=2636(int multi,) set void AutoCSetMulti=2636(int multi,)
# Retrieve the effect of autocompleting when there are multiple selections.. # Retrieve the effect of autocompleting when there are multiple selections.
get int AutoCGetMulti=2637(,) get int AutoCGetMulti=2637(,)
enu Ordering=SC_ORDER_ enu Ordering=SC_ORDER_

View File

@ -1,8 +1,9 @@
/* Scintilla source code edit control */ /* Scintilla source code edit control */
/** @file ScintillaWidget.h /* @file ScintillaWidget.h
** Definition of Scintilla widget for GTK+. * Definition of Scintilla widget for GTK+.
** Only needed by GTK+ code but is harmless on other platforms. * Only needed by GTK+ code but is harmless on other platforms.
**/ * This comment is not a doc-comment as that causes warnings from g-ir-scanner.
*/
/* Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> /* Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
* The License.txt file describes the conditions under which this software may be distributed. */ * The License.txt file describes the conditions under which this software may be distributed. */
@ -19,8 +20,15 @@ extern "C" {
#define SCINTILLA_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, scintilla_get_type (), ScintillaClass) #define SCINTILLA_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, scintilla_get_type (), ScintillaClass)
#define IS_SCINTILLA(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, scintilla_get_type ()) #define IS_SCINTILLA(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, scintilla_get_type ())
#define SCINTILLA_TYPE_OBJECT (scintilla_object_get_type())
#define SCINTILLA_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SCINTILLA_TYPE_OBJECT, ScintillaObject))
#define SCINTILLA_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SCINTILLA_TYPE_OBJECT))
#define SCINTILLA_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SCINTILLA_TYPE_OBJECT, ScintillaObjectClass))
#define SCINTILLA_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SCINTILLA_TYPE_OBJECT))
#define SCINTILLA_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SCINTILLA_TYPE_OBJECT, ScintillaObjectClass))
typedef struct _ScintillaObject ScintillaObject; typedef struct _ScintillaObject ScintillaObject;
typedef struct _ScintillaClass ScintillaClass; typedef struct _ScintillaClass ScintillaObjectClass;
struct _ScintillaObject { struct _ScintillaObject {
GtkContainer cont; GtkContainer cont;
@ -34,11 +42,20 @@ struct _ScintillaClass {
void (* notify) (ScintillaObject *ttt); void (* notify) (ScintillaObject *ttt);
}; };
GType scintilla_object_get_type (void);
GtkWidget* scintilla_object_new (void);
long scintilla_object_send_message (ScintillaObject *sci, unsigned int iMessage, guintptr wParam, gintptr lParam);
#ifndef G_IR_SCANNING
/* The legacy names confuse the g-ir-scanner program */
typedef struct _ScintillaClass ScintillaClass;
GType scintilla_get_type (void); GType scintilla_get_type (void);
GtkWidget* scintilla_new (void); GtkWidget* scintilla_new (void);
void scintilla_set_id (ScintillaObject *sci, uptr_t id); void scintilla_set_id (ScintillaObject *sci, uptr_t id);
sptr_t scintilla_send_message (ScintillaObject *sci,unsigned int iMessage, uptr_t wParam, sptr_t lParam); sptr_t scintilla_send_message (ScintillaObject *sci,unsigned int iMessage, uptr_t wParam, sptr_t lParam);
void scintilla_release_resources(void); void scintilla_release_resources(void);
#endif
#define SCINTILLA_NOTIFY "sci-notify" #define SCINTILLA_NOTIFY "sci-notify"

View File

@ -96,6 +96,19 @@ static int opposite(int ch) {
return ch; return ch;
} }
static int GlobScan(StyleContext &sc) {
// forward scan for a glob-like (...), no whitespace allowed
int c, sLen = 0;
while ((c = sc.GetRelativeCharacter(++sLen)) != 0) {
if (IsASpace(c)) {
return 0;
} else if (c == ')') {
return sLen;
}
}
return 0;
}
static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
WordList *keywordlists[], Accessor &styler) { WordList *keywordlists[], Accessor &styler) {
@ -113,9 +126,9 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
CharacterSet setBashOperator(CharacterSet::setNone, "^&%()-+=|{}[]:;>,*/<?!.~@"); CharacterSet setBashOperator(CharacterSet::setNone, "^&%()-+=|{}[]:;>,*/<?!.~@");
CharacterSet setSingleCharOp(CharacterSet::setNone, "rwxoRWXOezsfdlpSbctugkTBMACahGLNn"); CharacterSet setSingleCharOp(CharacterSet::setNone, "rwxoRWXOezsfdlpSbctugkTBMACahGLNn");
CharacterSet setParam(CharacterSet::setAlphaNum, "$_"); CharacterSet setParam(CharacterSet::setAlphaNum, "$_");
CharacterSet setHereDoc(CharacterSet::setAlpha, "_\\-+!"); CharacterSet setHereDoc(CharacterSet::setAlpha, "_\\-+!%*,./:?@[]^`{}~");
CharacterSet setHereDoc2(CharacterSet::setAlphaNum, "_-+!"); CharacterSet setHereDoc2(CharacterSet::setAlphaNum, "_-+!%*,./:=?@[]^`{}~");
CharacterSet setLeftShift(CharacterSet::setDigits, "=$"); CharacterSet setLeftShift(CharacterSet::setDigits, "$");
class HereDocCls { // Class to manage HERE document elements class HereDocCls { // Class to manage HERE document elements
public: public:
@ -126,14 +139,13 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
bool Quoted; // true if Quote in ('\'','"','`') bool Quoted; // true if Quote in ('\'','"','`')
bool Indent; // indented delimiter (for <<-) bool Indent; // indented delimiter (for <<-)
int DelimiterLength; // strlen(Delimiter) int DelimiterLength; // strlen(Delimiter)
char *Delimiter; // the Delimiter, 256: sizeof PL_tokenbuf char Delimiter[HERE_DELIM_MAX]; // the Delimiter
HereDocCls() { HereDocCls() {
State = 0; State = 0;
Quote = 0; Quote = 0;
Quoted = false; Quoted = false;
Indent = 0; Indent = 0;
DelimiterLength = 0; DelimiterLength = 0;
Delimiter = new char[HERE_DELIM_MAX];
Delimiter[0] = '\0'; Delimiter[0] = '\0';
} }
void Append(int ch) { void Append(int ch) {
@ -141,7 +153,6 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
Delimiter[DelimiterLength] = '\0'; Delimiter[DelimiterLength] = '\0';
} }
~HereDocCls() { ~HereDocCls() {
delete []Delimiter;
} }
}; };
HereDocCls HereDoc; HereDocCls HereDoc;
@ -173,18 +184,15 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
int Up, Down; int Up, Down;
int Style; int Style;
int Depth; // levels pushed int Depth; // levels pushed
int *CountStack; int CountStack[BASH_DELIM_STACK_MAX];
int *UpStack; int UpStack [BASH_DELIM_STACK_MAX];
int *StyleStack; int StyleStack[BASH_DELIM_STACK_MAX];
QuoteStackCls() { QuoteStackCls() {
Count = 0; Count = 0;
Up = '\0'; Up = '\0';
Down = '\0'; Down = '\0';
Style = 0; Style = 0;
Depth = 0; Depth = 0;
CountStack = new int[BASH_DELIM_STACK_MAX];
UpStack = new int[BASH_DELIM_STACK_MAX];
StyleStack = new int[BASH_DELIM_STACK_MAX];
} }
void Start(int u, int s) { void Start(int u, int s) {
Count = 1; Count = 1;
@ -214,9 +222,6 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
Down = opposite(Up); Down = opposite(Up);
} }
~QuoteStackCls() { ~QuoteStackCls() {
delete []CountStack;
delete []UpStack;
delete []StyleStack;
} }
}; };
QuoteStackCls QuoteStack; QuoteStackCls QuoteStack;
@ -345,6 +350,8 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
sc.ForwardSetState(SCE_SH_DEFAULT); sc.ForwardSetState(SCE_SH_DEFAULT);
} else if (!setWord.Contains(sc.ch)) { } else if (!setWord.Contains(sc.ch)) {
sc.SetState(SCE_SH_DEFAULT); sc.SetState(SCE_SH_DEFAULT);
} else if (cmdState == BASH_CMD_ARITH && !setWordStart.Contains(sc.ch)) {
sc.SetState(SCE_SH_DEFAULT);
} }
break; break;
case SCE_SH_NUMBER: case SCE_SH_NUMBER:
@ -419,17 +426,18 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
sc.Forward(); sc.Forward();
HereDoc.Quoted = true; HereDoc.Quoted = true;
HereDoc.State = 1; HereDoc.State = 1;
} else if (setHereDoc.Contains(sc.chNext)) { } else if (setHereDoc.Contains(sc.chNext) ||
(sc.chNext == '=' && cmdState != BASH_CMD_ARITH)) {
// an unquoted here-doc delimiter, no special handling // an unquoted here-doc delimiter, no special handling
// TODO check what exactly bash considers part of the delim
HereDoc.State = 1; HereDoc.State = 1;
} else if (sc.chNext == '<') { // HERE string <<< } else if (sc.chNext == '<') { // HERE string <<<
sc.Forward(); sc.Forward();
sc.ForwardSetState(SCE_SH_DEFAULT); sc.ForwardSetState(SCE_SH_DEFAULT);
} else if (IsASpace(sc.chNext)) { } else if (IsASpace(sc.chNext)) {
// eat whitespace // eat whitespace
} else if (setLeftShift.Contains(sc.chNext)) { } else if (setLeftShift.Contains(sc.chNext) ||
// left shift << or <<= operator cases (sc.chNext == '=' && cmdState == BASH_CMD_ARITH)) {
// left shift <<$var or <<= cases
sc.ChangeState(SCE_SH_OPERATOR); sc.ChangeState(SCE_SH_OPERATOR);
sc.ForwardSetState(SCE_SH_DEFAULT); sc.ForwardSetState(SCE_SH_DEFAULT);
} else { } else {
@ -584,12 +592,14 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
HereDoc.State = 2; HereDoc.State = 2;
if (HereDoc.Quoted) { if (HereDoc.Quoted) {
if (sc.state == SCE_SH_HERE_DELIM) { if (sc.state == SCE_SH_HERE_DELIM) {
// Missing quote at end of string! We are stricter than bash. // Missing quote at end of string! Syntax error in bash 4.3
// Colour here-doc anyway while marking this bit as an error. // Mark this bit as an error, do not colour any here-doc
sc.ChangeState(SCE_SH_ERROR); sc.ChangeState(SCE_SH_ERROR);
sc.SetState(SCE_SH_DEFAULT);
} else {
// HereDoc.Quote always == '\''
sc.SetState(SCE_SH_HERE_Q);
} }
// HereDoc.Quote always == '\''
sc.SetState(SCE_SH_HERE_Q);
} else if (HereDoc.DelimiterLength == 0) { } else if (HereDoc.DelimiterLength == 0) {
// no delimiter, illegal (but '' and "" are legal) // no delimiter, illegal (but '' and "" are legal)
sc.ChangeState(SCE_SH_ERROR); sc.ChangeState(SCE_SH_ERROR);
@ -634,6 +644,23 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
} else { } else {
sc.SetState(SCE_SH_WORD); sc.SetState(SCE_SH_WORD);
} }
// handle some zsh features within arithmetic expressions only
if (cmdState == BASH_CMD_ARITH) {
if (sc.chPrev == '[') { // [#8] [##8] output digit setting
sc.SetState(SCE_SH_WORD);
if (sc.chNext == '#') {
sc.Forward();
}
} else if (sc.Match("##^") && IsUpperCase(sc.GetRelative(3))) { // ##^A
sc.SetState(SCE_SH_IDENTIFIER);
sc.Forward(3);
} else if (sc.chNext == '#' && !IsASpace(sc.GetRelative(2))) { // ##a
sc.SetState(SCE_SH_IDENTIFIER);
sc.Forward(2);
} else if (setWordStart.Contains(sc.chNext)) { // #name
sc.SetState(SCE_SH_IDENTIFIER);
}
}
} else if (sc.ch == '\"') { } else if (sc.ch == '\"') {
sc.SetState(SCE_SH_STRING); sc.SetState(SCE_SH_STRING);
QuoteStack.Start(sc.ch, BASH_DELIM_STRING); QuoteStack.Start(sc.ch, BASH_DELIM_STRING);
@ -687,6 +714,15 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in
char s[10]; char s[10];
bool isCmdDelim = false; bool isCmdDelim = false;
sc.SetState(SCE_SH_OPERATOR); sc.SetState(SCE_SH_OPERATOR);
// globs have no whitespace, do not appear in arithmetic expressions
if (cmdState != BASH_CMD_ARITH && sc.ch == '(' && sc.chNext != '(') {
int i = GlobScan(sc);
if (i > 1) {
sc.SetState(SCE_SH_IDENTIFIER);
sc.Forward(i);
continue;
}
}
// handle opening delimiters for test/arithmetic expressions - ((,[[,[ // handle opening delimiters for test/arithmetic expressions - ((,[[,[
if (cmdState == BASH_CMD_START if (cmdState == BASH_CMD_START
|| cmdState == BASH_CMD_BODY) { || cmdState == BASH_CMD_BODY) {

View File

@ -112,7 +112,7 @@ long Platform::SendScintillaPointer(WindowID w, unsigned int msg, unsigned long
void EXT_LEXER_DECL Fold(unsigned int lexer, Sci_PositionU startPos, Sci_Position length, void EXT_LEXER_DECL Fold(unsigned int lexer, Sci_PositionU startPos, Sci_Position length,
int initStyle, char *words[], WindowID window, char *props) int initStyle, char *words[], WindowID window, char *props)
{ {
// below useless evaluation(s) to suppress "not used" warnings // below useless evaluation(s) to supress "not used" warnings
lexer; lexer;
// build expected data structures and do the Fold // build expected data structures and do the Fold
InternalLexOrFold(1, startPos, length, initStyle, words, window, props); InternalLexOrFold(1, startPos, length, initStyle, words, window, props);
@ -126,7 +126,7 @@ int EXT_LEXER_DECL GetLexerCount()
void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength) void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength)
{ {
// below useless evaluation(s) to suppress "not used" warnings // below useless evaluation(s) to supress "not used" warnings
Index; Index;
// return as much of our lexer name as will fit (what's up with Index?) // return as much of our lexer name as will fit (what's up with Index?)
if (buflength > 0) { if (buflength > 0) {
@ -141,7 +141,7 @@ void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength)
void EXT_LEXER_DECL Lex(unsigned int lexer, Sci_PositionU startPos, Sci_Position length, void EXT_LEXER_DECL Lex(unsigned int lexer, Sci_PositionU startPos, Sci_Position length,
int initStyle, char *words[], WindowID window, char *props) int initStyle, char *words[], WindowID window, char *props)
{ {
// below useless evaluation(s) to suppress "not used" warnings // below useless evaluation(s) to supress "not used" warnings
lexer; lexer;
// build expected data structures and do the Lex // build expected data structures and do the Lex
InternalLexOrFold(0, startPos, length, initStyle, words, window, props); InternalLexOrFold(0, startPos, length, initStyle, words, window, props);

View File

@ -54,7 +54,7 @@ static bool CmakeNextLineHasElse(Sci_PositionU start, Sci_PositionU end, Accesso
} }
} }
if ( nNextLine == -1 ) // We never found the next line... if ( nNextLine == -1 ) // We never foudn the next line...
return false; return false;
for ( Sci_PositionU firstChar = nNextLine; firstChar < end; firstChar++ ) { for ( Sci_PositionU firstChar = nNextLine; firstChar < end; firstChar++ ) {

View File

@ -64,7 +64,7 @@ static void ColouriseLuaDoc(
// but probably enough in most cases. [pP] is for hex floats. // but probably enough in most cases. [pP] is for hex floats.
CharacterSet setNumber(CharacterSet::setDigits, ".-+abcdefpABCDEFP"); CharacterSet setNumber(CharacterSet::setDigits, ".-+abcdefpABCDEFP");
CharacterSet setExponent(CharacterSet::setNone, "eEpP"); CharacterSet setExponent(CharacterSet::setNone, "eEpP");
CharacterSet setLuaOperator(CharacterSet::setNone, "*/-+()={}~[];<>,.^%:#"); CharacterSet setLuaOperator(CharacterSet::setNone, "*/-+()={}~[];<>,.^%:#&|");
CharacterSet setEscapeSkip(CharacterSet::setNone, "\"'\\"); CharacterSet setEscapeSkip(CharacterSet::setNone, "\"'\\");
Sci_Position currentLine = styler.GetLine(startPos); Sci_Position currentLine = styler.GetLine(startPos);

View File

@ -52,10 +52,10 @@ using namespace Scintilla;
#define HERE_DELIM_MAX 256 // maximum length of HERE doc delimiter #define HERE_DELIM_MAX 256 // maximum length of HERE doc delimiter
#define PERLNUM_BINARY 1 // order is significant: 1-4 cannot have a dot #define PERLNUM_BINARY 1 // order is significant: 1-3 cannot have a dot
#define PERLNUM_HEX 2 #define PERLNUM_OCTAL 2
#define PERLNUM_OCTAL 3 #define PERLNUM_FLOAT_EXP 3 // exponent part only
#define PERLNUM_FLOAT_EXP 4 // exponent part only #define PERLNUM_HEX 4 // may be a hex float
#define PERLNUM_DECIMAL 5 // 1-5 are numbers; 6-7 are strings #define PERLNUM_DECIMAL 5 // 1-5 are numbers; 6-7 are strings
#define PERLNUM_VECTOR 6 #define PERLNUM_VECTOR 6
#define PERLNUM_V_VECTOR 7 #define PERLNUM_V_VECTOR 7
@ -65,6 +65,12 @@ using namespace Scintilla;
#define BACK_OPERATOR 1 // whitespace/comments are insignificant #define BACK_OPERATOR 1 // whitespace/comments are insignificant
#define BACK_KEYWORD 2 // operators/keywords are needed for disambiguation #define BACK_KEYWORD 2 // operators/keywords are needed for disambiguation
#define SUB_BEGIN 0 // states for subroutine prototype scan:
#define SUB_HAS_PROTO 1 // only 'prototype' attribute allows prototypes
#define SUB_HAS_ATTRIB 2 // other attributes can exist leftward
#define SUB_HAS_MODULE 3 // sub name can have a ::identifier part
#define SUB_HAS_SUB 4 // 'sub' keyword
// all interpolated styles are different from their parent styles by a constant difference // all interpolated styles are different from their parent styles by a constant difference
// we also assume SCE_PL_STRING_VAR is the interpolated style with the smallest value // we also assume SCE_PL_STRING_VAR is the interpolated style with the smallest value
#define INTERPOLATE_SHIFT (SCE_PL_STRING_VAR - SCE_PL_STRING) #define INTERPOLATE_SHIFT (SCE_PL_STRING_VAR - SCE_PL_STRING)
@ -105,9 +111,11 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit
// &bareword: subroutine call // &bareword: subroutine call
|| styler.Match(bk - 1, "->") || styler.Match(bk - 1, "->")
// ->bareword: part of variable spec // ->bareword: part of variable spec
|| styler.Match(bk - 1, "::")
// ::bareword: part of module spec
|| styler.Match(bk - 2, "sub")) { || styler.Match(bk - 2, "sub")) {
// sub bareword: subroutine declaration // sub bareword: subroutine declaration
// (implied BACK_KEYWORD, no keywords end in 'sub'!) // (implied BACK_KEYWORD, no keywords end in 'sub'!)
result |= 1; result |= 1;
} }
// next, scan forward after word past tab/spaces only; // next, scan forward after word past tab/spaces only;
@ -121,7 +129,7 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit
if ((ch == '}' && brace) if ((ch == '}' && brace)
// {bareword}: variable spec // {bareword}: variable spec
|| styler.Match(fw, "=>")) { || styler.Match(fw, "=>")) {
// [{(, bareword=>: hash literal // [{(, bareword=>: hash literal
result |= 2; result |= 2;
} }
} }
@ -136,6 +144,22 @@ static void skipWhitespaceComment(LexAccessor &styler, Sci_PositionU &p) {
p--; p--;
} }
static int findPrevLexeme(LexAccessor &styler, Sci_PositionU &bk, int &style) {
// scan backward past whitespace and comments to find a lexeme
skipWhitespaceComment(styler, bk);
if (bk == 0)
return 0;
int sz = 1;
style = styler.StyleAt(bk);
while (bk > 0) { // find extent of lexeme
if (styler.StyleAt(bk - 1) == style) {
bk--; sz++;
} else
break;
}
return sz;
}
static int styleBeforeBracePair(LexAccessor &styler, Sci_PositionU bk) { static int styleBeforeBracePair(LexAccessor &styler, Sci_PositionU bk) {
// backtrack to find open '{' corresponding to a '}', balanced // backtrack to find open '{' corresponding to a '}', balanced
// return significant style to be tested for '/' disambiguation // return significant style to be tested for '/' disambiguation
@ -214,20 +238,59 @@ static int podLineScan(LexAccessor &styler, Sci_PositionU &pos, Sci_PositionU en
static bool styleCheckSubPrototype(LexAccessor &styler, Sci_PositionU bk) { static bool styleCheckSubPrototype(LexAccessor &styler, Sci_PositionU bk) {
// backtrack to identify if we're starting a subroutine prototype // backtrack to identify if we're starting a subroutine prototype
// we also need to ignore whitespace/comments: // we also need to ignore whitespace/comments, format is like:
// 'sub' [whitespace|comment] <identifier> [whitespace|comment] // sub abc::pqr :const :prototype(...)
// lexemes are tested in pairs, e.g. '::'+'pqr', ':'+'const', etc.
// and a state machine generates legal subroutine syntax matches
styler.Flush(); styler.Flush();
skipWhitespaceComment(styler, bk); int state = SUB_BEGIN;
if (bk == 0 || styler.StyleAt(bk) != SCE_PL_IDENTIFIER) // check identifier do {
return false; // find two lexemes, lexeme 2 follows lexeme 1
while (bk > 0 && (styler.StyleAt(bk) == SCE_PL_IDENTIFIER)) { int style2 = SCE_PL_DEFAULT;
bk--; Sci_PositionU pos2 = bk;
} int len2 = findPrevLexeme(styler, pos2, style2);
skipWhitespaceComment(styler, bk); int style1 = SCE_PL_DEFAULT;
if (bk < 2 || styler.StyleAt(bk) != SCE_PL_WORD // check "sub" keyword Sci_PositionU pos1 = pos2;
|| !styler.Match(bk - 2, "sub")) // assume suffix is unique! if (pos1 > 0) pos1--;
return false; int len1 = findPrevLexeme(styler, pos1, style1);
return true; if (len1 == 0 || len2 == 0) // lexeme pair must exist
break;
// match parts of syntax, if invalid subroutine syntax, break off
if (style1 == SCE_PL_OPERATOR && len1 == 1 &&
styler.SafeGetCharAt(pos1) == ':') { // ':'
if (style2 == SCE_PL_IDENTIFIER || style2 == SCE_PL_WORD) {
if (len2 == 9 && styler.Match(pos2, "prototype")) { // ':' 'prototype'
if (state == SUB_BEGIN) {
state = SUB_HAS_PROTO;
} else
break;
} else { // ':' <attribute>
if (state == SUB_HAS_PROTO || state == SUB_HAS_ATTRIB) {
state = SUB_HAS_ATTRIB;
} else
break;
}
} else
break;
} else if (style1 == SCE_PL_OPERATOR && len1 == 2 &&
styler.Match(pos1, "::")) { // '::'
if (style2 == SCE_PL_IDENTIFIER) { // '::' <identifier>
state = SUB_HAS_MODULE;
} else
break;
} else if (style1 == SCE_PL_WORD && len1 == 3 &&
styler.Match(pos1, "sub")) { // 'sub'
if (style2 == SCE_PL_IDENTIFIER) { // 'sub' <identifier>
state = SUB_HAS_SUB;
} else
break;
} else
break;
bk = pos1; // set position for finding next lexeme pair
if (bk > 0) bk--;
} while (state != SUB_HAS_SUB);
return (state == SUB_HAS_SUB);
} }
static int actualNumStyle(int numberStyle) { static int actualNumStyle(int numberStyle) {
@ -537,7 +600,8 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
CharacterSet &setPOD = setModifiers; CharacterSet &setPOD = setModifiers;
CharacterSet setNonHereDoc(CharacterSet::setDigits, "=$@"); CharacterSet setNonHereDoc(CharacterSet::setDigits, "=$@");
CharacterSet setHereDocDelim(CharacterSet::setAlphaNum, "_"); CharacterSet setHereDocDelim(CharacterSet::setAlphaNum, "_");
CharacterSet setSubPrototype(CharacterSet::setNone, "\\[$@%&*+];"); CharacterSet setSubPrototype(CharacterSet::setNone, "\\[$@%&*+];_ \t");
CharacterSet setRepetition(CharacterSet::setDigits, ")\"'");
// for format identifiers // for format identifiers
CharacterSet setFormatStart(CharacterSet::setAlpha, "_="); CharacterSet setFormatStart(CharacterSet::setAlpha, "_=");
CharacterSet &setFormat = setHereDocDelim; CharacterSet &setFormat = setHereDocDelim;
@ -555,13 +619,12 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
int Quote; // the char after '<<' int Quote; // the char after '<<'
bool Quoted; // true if Quote in ('\'','"','`') bool Quoted; // true if Quote in ('\'','"','`')
int DelimiterLength; // strlen(Delimiter) int DelimiterLength; // strlen(Delimiter)
char *Delimiter; // the Delimiter, 256: sizeof PL_tokenbuf char Delimiter[HERE_DELIM_MAX]; // the Delimiter
HereDocCls() { HereDocCls() {
State = 0; State = 0;
Quote = 0; Quote = 0;
Quoted = false; Quoted = false;
DelimiterLength = 0; DelimiterLength = 0;
Delimiter = new char[HERE_DELIM_MAX];
Delimiter[0] = '\0'; Delimiter[0] = '\0';
} }
void Append(int ch) { void Append(int ch) {
@ -569,7 +632,6 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
Delimiter[DelimiterLength] = '\0'; Delimiter[DelimiterLength] = '\0';
} }
~HereDocCls() { ~HereDocCls() {
delete []Delimiter;
} }
}; };
HereDocCls HereDoc; // TODO: FIFO for stacked here-docs HereDocCls HereDoc; // TODO: FIFO for stacked here-docs
@ -762,6 +824,14 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
break; break;
} }
// number then dot (go through) // number then dot (go through)
} else if (numState == PERLNUM_HEX) {
if (dotCount <= 1 && IsADigit(sc.chNext, 16)) {
break; // hex with one dot is a hex float
} else {
sc.SetState(SCE_PL_OPERATOR);
break;
}
// hex then dot (go through)
} else if (IsADigit(sc.chNext)) // vectors } else if (IsADigit(sc.chNext)) // vectors
break; break;
// vector then dot (go through) // vector then dot (go through)
@ -780,8 +850,15 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
break; break;
// number then word (go through) // number then word (go through)
} else if (numState == PERLNUM_HEX) { } else if (numState == PERLNUM_HEX) {
if (IsADigit(sc.ch, 16)) if (sc.ch == 'P' || sc.ch == 'p') { // hex float exponent, sign
numState = PERLNUM_FLOAT_EXP;
if (sc.chNext == '+' || sc.chNext == '-') {
sc.Forward();
}
break; break;
} else if (IsADigit(sc.ch, 16))
break;
// hex or hex float then word (go through)
} else if (numState == PERLNUM_VECTOR || numState == PERLNUM_V_VECTOR) { } else if (numState == PERLNUM_VECTOR || numState == PERLNUM_V_VECTOR) {
if (IsADigit(sc.ch)) // vector if (IsADigit(sc.ch)) // vector
break; break;
@ -1265,7 +1342,7 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
fw++; fw++;
} else if (sc.ch == 'x' && (sc.chNext == '=' || // repetition } else if (sc.ch == 'x' && (sc.chNext == '=' || // repetition
!setWord.Contains(sc.chNext) || !setWord.Contains(sc.chNext) ||
(IsADigit(sc.chPrev) && IsADigit(sc.chNext)))) { (setRepetition.Contains(sc.chPrev) && IsADigit(sc.chNext)))) {
sc.ChangeState(SCE_PL_OPERATOR); sc.ChangeState(SCE_PL_OPERATOR);
} }
// if potentially a keyword, scan forward and grab word, then check // if potentially a keyword, scan forward and grab word, then check
@ -1438,7 +1515,10 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
} }
backFlag = BACK_NONE; backFlag = BACK_NONE;
if (isHereDoc) { // handle '<<', HERE doc if (isHereDoc) { // handle '<<', HERE doc
if (preferRE) { if (sc.Match("<<>>")) { // double-diamond operator (5.22)
sc.SetState(SCE_PL_OPERATOR);
sc.Forward(3);
} else if (preferRE) {
sc.SetState(SCE_PL_HERE_DELIM); sc.SetState(SCE_PL_HERE_DELIM);
HereDoc.State = 0; HereDoc.State = 0;
} else { // << operator } else { // << operator

View File

@ -4,26 +4,26 @@ diff --git scintilla/gtk/ScintillaGTK.cxx scintilla/gtk/ScintillaGTK.cxx
index 0871ca2..49dc278 100644 index 0871ca2..49dc278 100644
--- scintilla/gtk/ScintillaGTK.cxx --- scintilla/gtk/ScintillaGTK.cxx
+++ scintilla/gtk/ScintillaGTK.cxx +++ scintilla/gtk/ScintillaGTK.cxx
@@ -3104,6 +3104,7 @@ sptr_t ScintillaGTK::DirectFunction( @@ -3046,6 +3046,7 @@ sptr_t ScintillaGTK::DirectFunction(
return reinterpret_cast<ScintillaGTK *>(ptr)->WndProc(iMessage, wParam, lParam);
} }
/* legacy name for scintilla_object_send_message */
+GEANY_API_SYMBOL +GEANY_API_SYMBOL
sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin); ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin);
return psci->WndProc(iMessage, wParam, lParam); return psci->WndProc(iMessage, wParam, lParam);
@@ -3115,6 +3116,7 @@ static void scintilla_init(ScintillaObject *sci); @@ -3062,6 +3062,7 @@ extern void Platform_Initialise();
extern void Platform_Initialise();
extern void Platform_Finalise(); extern void Platform_Finalise();
/* legacy name for scintilla_object_get_type */
+GEANY_API_SYMBOL +GEANY_API_SYMBOL
GType scintilla_get_type() { GType scintilla_get_type() {
static GType scintilla_type = 0; static GType scintilla_type = 0;
try { try {
@@ -3252,6 +3254,7 @@ static void scintilla_init(ScintillaObject *sci) { @@ -3200,6 +3200,7 @@ static void scintilla_init(ScintillaObject *sci) {
}
} }
/* legacy name for scintilla_object_new */
+GEANY_API_SYMBOL +GEANY_API_SYMBOL
GtkWidget* scintilla_new() { GtkWidget* scintilla_new() {
GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL)); GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL));
@ -57,10 +57,10 @@ index be57b7c..cee3e73 100644
{ {
typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1, typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1,
diff --git scintilla/src/Catalogue.cxx scintilla/src/Catalogue.cxx diff --git scintilla/src/Catalogue.cxx scintilla/src/Catalogue.cxx
index b02a010..400d423 100644 index ed47aa8..e58f1ab 100644
--- scintilla/src/Catalogue.cxx --- scintilla/src/Catalogue.cxx
+++ scintilla/src/Catalogue.cxx +++ scintilla/src/Catalogue.cxx
@@ -76,120 +76,50 @@ int Scintilla_LinkLexers() { @@ -77,120 +77,50 @@ int Scintilla_LinkLexers() {
//++Autogenerated -- run scripts/LexGen.py to regenerate //++Autogenerated -- run scripts/LexGen.py to regenerate
//**\(\tLINK_LEXER(\*);\n\) //**\(\tLINK_LEXER(\*);\n\)

View File

@ -496,6 +496,25 @@ void CellBuffer::SetLineEndTypes(int utf8LineEnds_) {
} }
} }
bool CellBuffer::ContainsLineEnd(const char *s, int length) const {
unsigned char chBeforePrev = 0;
unsigned char chPrev = 0;
for (int i = 0; i < length; i++) {
const unsigned char ch = s[i];
if ((ch == '\r') || (ch == '\n')) {
return true;
} else if (utf8LineEnds) {
unsigned char back3[3] = { chBeforePrev, chPrev, ch };
if (UTF8IsSeparator(back3) || UTF8IsNEL(back3 + 1)) {
return true;
}
}
chBeforePrev = chPrev;
chPrev = ch;
}
return false;
}
void CellBuffer::SetPerLine(PerLine *pl) { void CellBuffer::SetPerLine(PerLine *pl) {
lv.SetPerLine(pl); lv.SetPerLine(pl);
} }

View File

@ -177,6 +177,7 @@ public:
void Allocate(int newSize); void Allocate(int newSize);
int GetLineEndTypes() const { return utf8LineEnds; } int GetLineEndTypes() const { return utf8LineEnds; }
void SetLineEndTypes(int utf8LineEnds_); void SetLineEndTypes(int utf8LineEnds_);
bool ContainsLineEnd(const char *s, int length) const;
void SetPerLine(PerLine *pl); void SetPerLine(PerLine *pl);
int Lines() const; int Lines() const;
int LineStart(int line) const; int LineStart(int line) const;

View File

@ -109,6 +109,7 @@ Document::Document() {
useTabs = true; useTabs = true;
tabIndents = true; tabIndents = true;
backspaceUnindents = false; backspaceUnindents = false;
durationStyleOneLine = 0.00001;
matchesValid = false; matchesValid = false;
regex = 0; regex = 0;
@ -1892,6 +1893,33 @@ void Document::EnsureStyledTo(int pos) {
} }
} }
void Document::StyleToAdjustingLineDuration(int pos) {
// Place bounds on the duration used to avoid glitches spiking it
// and so causing slow styling or non-responsive scrolling
const double minDurationOneLine = 0.000001;
const double maxDurationOneLine = 0.0001;
// Alpha value for exponential smoothing.
// Most recent value contributes 25% to smoothed value.
const double alpha = 0.25;
const Sci_Position lineFirst = LineFromPosition(GetEndStyled());
ElapsedTime etStyling;
EnsureStyledTo(pos);
const double durationStyling = etStyling.Duration();
const Sci_Position lineLast = LineFromPosition(GetEndStyled());
if (lineLast >= lineFirst + 8) {
// Only adjust for styling multiple lines to avoid instability
const double durationOneLine = durationStyling / (lineLast - lineFirst);
durationStyleOneLine = alpha * durationOneLine + (1.0 - alpha) * durationStyleOneLine;
if (durationStyleOneLine < minDurationOneLine) {
durationStyleOneLine = minDurationOneLine;
} else if (durationStyleOneLine > maxDurationOneLine) {
durationStyleOneLine = maxDurationOneLine;
}
}
}
void Document::LexerChanged() { void Document::LexerChanged() {
// Tell the watchers the lexer has changed. // Tell the watchers the lexer has changed.
for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) { for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
@ -2187,7 +2215,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) {
char chSeek = BraceOpposite(chBrace); char chSeek = BraceOpposite(chBrace);
if (chSeek == '\0') if (chSeek == '\0')
return - 1; return - 1;
char styBrace = static_cast<char>(StyleAt(position)); const int styBrace = StyleIndexAt(position);
int direction = -1; int direction = -1;
if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<')
direction = 1; direction = 1;
@ -2195,7 +2223,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) {
position = NextPosition(position, direction); position = NextPosition(position, direction);
while ((position >= 0) && (position < Length())) { while ((position >= 0) && (position < Length())) {
char chAtPos = CharAt(position); char chAtPos = CharAt(position);
char styAtPos = static_cast<char>(StyleAt(position)); const int styAtPos = StyleIndexAt(position);
if ((position > GetEndStyled()) || (styAtPos == styBrace)) { if ((position > GetEndStyled()) || (styAtPos == styBrace)) {
if (chAtPos == chBrace) if (chAtPos == chBrace)
depth++; depth++;

View File

@ -246,6 +246,7 @@ public:
bool useTabs; bool useTabs;
bool tabIndents; bool tabIndents;
bool backspaceUnindents; bool backspaceUnindents;
double durationStyleOneLine;
DecorationList decorations; DecorationList decorations;
@ -272,6 +273,7 @@ public:
Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const; Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const;
int ClampPositionIntoDocument(int pos) const; int ClampPositionIntoDocument(int pos) const;
bool ContainsLineEnd(const char *s, int length) const { return cb.ContainsLineEnd(s, length); }
bool IsCrLf(int pos) const; bool IsCrLf(int pos) const;
int LenChar(int pos); int LenChar(int pos);
bool InGoodUTF8(int pos, int &start, int &end) const; bool InGoodUTF8(int pos, int &start, int &end) const;
@ -339,6 +341,7 @@ public:
cb.GetCharRange(buffer, position, lengthRetrieve); cb.GetCharRange(buffer, position, lengthRetrieve);
} }
char SCI_METHOD StyleAt(Sci_Position position) const { return cb.StyleAt(position); } char SCI_METHOD StyleAt(Sci_Position position) const { return cb.StyleAt(position); }
int StyleIndexAt(Sci_Position position) const { return static_cast<unsigned char>(cb.StyleAt(position)); }
void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const { void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const {
cb.GetStyleRange(buffer, position, lengthRetrieve); cb.GetStyleRange(buffer, position, lengthRetrieve);
} }
@ -400,6 +403,7 @@ public:
bool SCI_METHOD SetStyles(Sci_Position length, const char *styles); bool SCI_METHOD SetStyles(Sci_Position length, const char *styles);
int GetEndStyled() const { return endStyled; } int GetEndStyled() const { return endStyled; }
void EnsureStyledTo(int pos); void EnsureStyledTo(int pos);
void StyleToAdjustingLineDuration(int pos);
void LexerChanged(); void LexerChanged();
int GetStyleClock() const { return styleClock; } int GetStyleClock() const { return styleClock; }
void IncrementStyleClock(); void IncrementStyleClock();

View File

@ -376,14 +376,14 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co
// See if chars, styles, indicators, are all the same // See if chars, styles, indicators, are all the same
bool allSame = true; bool allSame = true;
// Check base line layout // Check base line layout
char styleByte = 0; int styleByte = 0;
int numCharsInLine = 0; int numCharsInLine = 0;
while (numCharsInLine < lineLength) { while (numCharsInLine < lineLength) {
int charInDoc = numCharsInLine + posLineStart; int charInDoc = numCharsInLine + posLineStart;
char chDoc = model.pdoc->CharAt(charInDoc); char chDoc = model.pdoc->CharAt(charInDoc);
styleByte = model.pdoc->StyleAt(charInDoc); styleByte = model.pdoc->StyleIndexAt(charInDoc);
allSame = allSame && allSame = allSame &&
(ll->styles[numCharsInLine] == static_cast<unsigned char>(styleByte)); (ll->styles[numCharsInLine] == styleByte);
if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed) if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed)
allSame = allSame && allSame = allSame &&
(ll->chars[numCharsInLine] == chDoc); (ll->chars[numCharsInLine] == chDoc);
@ -986,11 +986,10 @@ static void DrawIndicators(Surface *surface, const EditModel &model, const ViewS
startPos = deco->rs.EndRun(startPos); startPos = deco->rs.EndRun(startPos);
} }
while ((startPos < posLineEnd) && (deco->rs.ValueAt(startPos))) { while ((startPos < posLineEnd) && (deco->rs.ValueAt(startPos))) {
int endPos = deco->rs.EndRun(startPos); const Range rangeRun(deco->rs.StartRun(startPos), deco->rs.EndRun(startPos));
if (endPos > posLineEnd) const int endPos = std::min(rangeRun.end, posLineEnd);
endPos = posLineEnd;
const bool hover = vsDraw.indicators[deco->indicator].IsDynamic() && const bool hover = vsDraw.indicators[deco->indicator].IsDynamic() &&
((hoverIndicatorPos >= startPos) && (hoverIndicatorPos <= endPos)); rangeRun.ContainsCharacter(hoverIndicatorPos);
const int value = deco->rs.ValueAt(startPos); const int value = deco->rs.ValueAt(startPos);
Indicator::DrawState drawState = hover ? Indicator::drawHover : Indicator::drawNormal; Indicator::DrawState drawState = hover ? Indicator::drawHover : Indicator::drawNormal;
DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart, DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart,

View File

@ -173,6 +173,8 @@ Editor::Editor() {
paintAbandonedByStyling = false; paintAbandonedByStyling = false;
paintingAllText = false; paintingAllText = false;
willRedrawAll = false; willRedrawAll = false;
idleStyling = SC_IDLESTYLING_NONE;
needIdleStyling = false;
modEventMask = SC_MODEVENTMASKALL; modEventMask = SC_MODEVENTMASKALL;
@ -762,7 +764,7 @@ bool Editor::RangeContainsProtected(int start, int end) const {
end = t; end = t;
} }
for (int pos = start; pos < end; pos++) { for (int pos = start; pos < end; pos++) {
if (vs.styles[pdoc->StyleAt(pos)].IsProtected()) if (vs.styles[pdoc->StyleIndexAt(pos)].IsProtected())
return true; return true;
} }
} }
@ -792,15 +794,15 @@ SelectionPosition Editor::MovePositionOutsideChar(SelectionPosition pos, int mov
pos.SetPosition(posMoved); pos.SetPosition(posMoved);
if (vs.ProtectionActive()) { if (vs.ProtectionActive()) {
if (moveDir > 0) { if (moveDir > 0) {
if ((pos.Position() > 0) && vs.styles[pdoc->StyleAt(pos.Position() - 1)].IsProtected()) { if ((pos.Position() > 0) && vs.styles[pdoc->StyleIndexAt(pos.Position() - 1)].IsProtected()) {
while ((pos.Position() < pdoc->Length()) && while ((pos.Position() < pdoc->Length()) &&
(vs.styles[pdoc->StyleAt(pos.Position())].IsProtected())) (vs.styles[pdoc->StyleIndexAt(pos.Position())].IsProtected()))
pos.Add(1); pos.Add(1);
} }
} else if (moveDir < 0) { } else if (moveDir < 0) {
if (vs.styles[pdoc->StyleAt(pos.Position())].IsProtected()) { if (vs.styles[pdoc->StyleIndexAt(pos.Position())].IsProtected()) {
while ((pos.Position() > 0) && while ((pos.Position() > 0) &&
(vs.styles[pdoc->StyleAt(pos.Position() - 1)].IsProtected())) (vs.styles[pdoc->StyleIndexAt(pos.Position() - 1)].IsProtected()))
pos.Add(-1); pos.Add(-1);
} }
} }
@ -919,7 +921,7 @@ void Editor::ScrollTo(int line, bool moveThumb) {
SetTopLine(topLineNew); SetTopLine(topLineNew);
// Optimize by styling the view as this will invalidate any needed area // Optimize by styling the view as this will invalidate any needed area
// which could abort the initial paint if discovered later. // which could abort the initial paint if discovered later.
StyleToPositionInView(PositionAfterArea(GetClientRectangle())); StyleAreaBounded(GetClientRectangle(), true);
#ifndef UNDER_CE #ifndef UNDER_CE
// Perform redraw rather than scroll if many lines would be redrawn anyway. // Perform redraw rather than scroll if many lines would be redrawn anyway.
if (performBlit) { if (performBlit) {
@ -1692,7 +1694,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
paintAbandonedByStyling = false; paintAbandonedByStyling = false;
StyleToPositionInView(PositionAfterArea(rcArea)); StyleAreaBounded(rcArea, false);
PRectangle rcClient = GetClientRectangle(); PRectangle rcClient = GetClientRectangle();
//Platform::DebugPrintf("Client: (%3d,%3d) ... (%3d,%3d) %d\n", //Platform::DebugPrintf("Client: (%3d,%3d) ... (%3d,%3d) %d\n",
@ -1954,6 +1956,8 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
void Editor::ClearBeforeTentativeStart() { void Editor::ClearBeforeTentativeStart() {
// Make positions for the first composition string. // Make positions for the first composition string.
FilterSelections();
UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty() || inOverstrike);
for (size_t r = 0; r<sel.Count(); r++) { for (size_t r = 0; r<sel.Count(); r++) {
if (!RangeContainsProtected(sel.Range(r).Start().Position(), if (!RangeContainsProtected(sel.Range(r).Start().Position(),
sel.Range(r).End().Position())) { sel.Range(r).End().Position())) {
@ -2575,21 +2579,24 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) {
} }
if ((mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) && cs.HiddenLines()) { if ((mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) && cs.HiddenLines()) {
// Some lines are hidden so may need shown. // Some lines are hidden so may need shown.
// TODO: check if the modified area is hidden. const int lineOfPos = pdoc->LineFromPosition(mh.position);
int endNeedShown = mh.position;
if (mh.modificationType & SC_MOD_BEFOREINSERT) { if (mh.modificationType & SC_MOD_BEFOREINSERT) {
int lineOfPos = pdoc->LineFromPosition(mh.position); if (pdoc->ContainsLineEnd(mh.text, mh.length) && (mh.position != pdoc->LineStart(lineOfPos)))
bool insertingNewLine = false; endNeedShown = pdoc->LineStart(lineOfPos+1);
for (int i=0; i < mh.length; i++) {
if ((mh.text[i] == '\n') || (mh.text[i] == '\r'))
insertingNewLine = true;
}
if (insertingNewLine && (mh.position != pdoc->LineStart(lineOfPos)))
NeedShown(mh.position, pdoc->LineStart(lineOfPos+1) - mh.position);
else
NeedShown(mh.position, 0);
} else if (mh.modificationType & SC_MOD_BEFOREDELETE) { } else if (mh.modificationType & SC_MOD_BEFOREDELETE) {
NeedShown(mh.position, mh.length); // Extend the need shown area over any folded lines
endNeedShown = mh.position + mh.length;
int lineLast = pdoc->LineFromPosition(mh.position+mh.length);
for (int line = lineOfPos; line <= lineLast; line++) {
const int lineMaxSubord = pdoc->GetLastChild(line, -1, -1);
if (lineLast < lineMaxSubord) {
lineLast = lineMaxSubord;
endNeedShown = pdoc->LineEnd(lineLast);
}
}
} }
NeedShown(mh.position, endNeedShown - mh.position);
} }
if (mh.linesAdded != 0) { if (mh.linesAdded != 0) {
// Update contraction state for inserted and removed lines // Update contraction state for inserted and removed lines
@ -4556,7 +4563,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b
} }
bool Editor::PositionIsHotspot(int position) const { bool Editor::PositionIsHotspot(int position) const {
return vs.styles[static_cast<unsigned char>(pdoc->StyleAt(position))].hotspot; return vs.styles[pdoc->StyleIndexAt(position)].hotspot;
} }
bool Editor::PointIsHotspot(Point pt) { bool Editor::PointIsHotspot(Point pt) {
@ -4581,10 +4588,7 @@ void Editor::SetHoverIndicatorPosition(int position) {
} }
} }
if (hoverIndicatorPosPrev != hoverIndicatorPos) { if (hoverIndicatorPosPrev != hoverIndicatorPos) {
if (hoverIndicatorPosPrev != INVALID_POSITION) Redraw();
InvalidateRange(hoverIndicatorPosPrev, hoverIndicatorPosPrev + 1);
if (hoverIndicatorPos != INVALID_POSITION)
InvalidateRange(hoverIndicatorPos, hoverIndicatorPos + 1);
} }
} }
@ -4882,17 +4886,15 @@ void Editor::Tick() {
} }
bool Editor::Idle() { bool Editor::Idle() {
bool needWrap = Wrapping() && wrapPending.NeedsWrap();
bool idleDone; if (needWrap) {
bool wrappingDone = !Wrapping();
if (!wrappingDone) {
// Wrap lines during idle. // Wrap lines during idle.
WrapLines(wsIdle); WrapLines(wsIdle);
// No more wrapping // No more wrapping
if (!wrapPending.NeedsWrap()) needWrap = wrapPending.NeedsWrap();
wrappingDone = true; } else if (needIdleStyling) {
IdleStyling();
} }
// Add more idle things to do here, but make sure idleDone is // Add more idle things to do here, but make sure idleDone is
@ -4900,7 +4902,7 @@ bool Editor::Idle() {
// false will stop calling this idle function until SetIdle() is // false will stop calling this idle function until SetIdle() is
// called again. // called again.
idleDone = wrappingDone; // && thatDone && theOtherThingDone... const bool idleDone = !needWrap && !needIdleStyling; // && thatDone && theOtherThingDone...
return !idleDone; return !idleDone;
} }
@ -4991,9 +4993,9 @@ void Editor::StyleToPositionInView(Position pos) {
int endWindow = PositionAfterArea(GetClientDrawingRectangle()); int endWindow = PositionAfterArea(GetClientDrawingRectangle());
if (pos > endWindow) if (pos > endWindow)
pos = endWindow; pos = endWindow;
int styleAtEnd = pdoc->StyleAt(pos-1); const int styleAtEnd = pdoc->StyleIndexAt(pos-1);
pdoc->EnsureStyledTo(pos); pdoc->EnsureStyledTo(pos);
if ((endWindow > pos) && (styleAtEnd != pdoc->StyleAt(pos-1))) { if ((endWindow > pos) && (styleAtEnd != pdoc->StyleIndexAt(pos-1))) {
// Style at end of line changed so is multi-line change like starting a comment // Style at end of line changed so is multi-line change like starting a comment
// so require rest of window to be styled. // so require rest of window to be styled.
DiscardOverdraw(); // Prepared bitmaps may be invalid DiscardOverdraw(); // Prepared bitmaps may be invalid
@ -5003,12 +5005,71 @@ void Editor::StyleToPositionInView(Position pos) {
} }
} }
int Editor::PositionAfterMaxStyling(int posMax, bool scrolling) const {
if ((idleStyling == SC_IDLESTYLING_NONE) || (idleStyling == SC_IDLESTYLING_AFTERVISIBLE)) {
// Both states do not limit styling
return posMax;
}
// Try to keep time taken by styling reasonable so interaction remains smooth.
// When scrolling, allow less time to ensure responsive
const double secondsAllowed = scrolling ? 0.005 : 0.02;
const int linesToStyle = Platform::Clamp(static_cast<int>(secondsAllowed / pdoc->durationStyleOneLine),
10, 0x10000);
const int stylingMaxLine = std::min(
static_cast<int>(pdoc->LineFromPosition(pdoc->GetEndStyled()) + linesToStyle),
pdoc->LinesTotal());
return std::min(static_cast<int>(pdoc->LineStart(stylingMaxLine)), posMax);
}
void Editor::StartIdleStyling(bool truncatedLastStyling) {
if ((idleStyling == SC_IDLESTYLING_ALL) || (idleStyling == SC_IDLESTYLING_AFTERVISIBLE)) {
if (pdoc->GetEndStyled() < pdoc->Length()) {
// Style remainder of document in idle time
needIdleStyling = true;
}
} else if (truncatedLastStyling) {
needIdleStyling = true;
}
if (needIdleStyling) {
SetIdle(true);
}
}
// Style for an area but bound the amount of styling to remain responsive
void Editor::StyleAreaBounded(PRectangle rcArea, bool scrolling) {
const int posAfterArea = PositionAfterArea(rcArea);
const int posAfterMax = PositionAfterMaxStyling(posAfterArea, scrolling);
if (posAfterMax < posAfterArea) {
// Idle styling may be performed before current visible area
// Style a bit now then style further in idle time
pdoc->StyleToAdjustingLineDuration(posAfterMax);
} else {
// Can style all wanted now.
StyleToPositionInView(posAfterArea);
}
StartIdleStyling(posAfterMax < posAfterArea);
}
void Editor::IdleStyling() {
const int posAfterArea = PositionAfterArea(GetClientRectangle());
const int endGoal = (idleStyling >= SC_IDLESTYLING_AFTERVISIBLE) ?
pdoc->Length() : posAfterArea;
const int posAfterMax = PositionAfterMaxStyling(endGoal, false);
pdoc->StyleToAdjustingLineDuration(posAfterMax);
if (pdoc->GetEndStyled() >= endGoal) {
needIdleStyling = false;
}
}
void Editor::IdleWork() { void Editor::IdleWork() {
// Style the line after the modification as this allows modifications that change just the // Style the line after the modification as this allows modifications that change just the
// line of the modification to heal instead of propagating to the rest of the window. // line of the modification to heal instead of propagating to the rest of the window.
if (workNeeded.items & WorkNeeded::workStyle) if (workNeeded.items & WorkNeeded::workStyle) {
StyleToPositionInView(pdoc->LineStart(pdoc->LineFromPosition(workNeeded.upTo) + 2)); StyleToPositionInView(pdoc->LineStart(pdoc->LineFromPosition(workNeeded.upTo) + 2));
}
NotifyUpdateUI(); NotifyUpdateUI();
workNeeded.Reset(); workNeeded.Reset();
} }
@ -6401,6 +6462,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_ISRANGEWORD: case SCI_ISRANGEWORD:
return pdoc->IsWordAt(static_cast<int>(wParam), static_cast<int>(lParam)); return pdoc->IsWordAt(static_cast<int>(wParam), static_cast<int>(lParam));
case SCI_SETIDLESTYLING:
idleStyling = static_cast<int>(wParam);
break;
case SCI_GETIDLESTYLING:
return idleStyling;
case SCI_SETWRAPMODE: case SCI_SETWRAPMODE:
if (vs.SetWrapState(static_cast<int>(wParam))) { if (vs.SetWrapState(static_cast<int>(wParam))) {
xOffset = 0; xOffset = 0;
@ -7760,6 +7828,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_CLEARSELECTIONS: case SCI_CLEARSELECTIONS:
sel.Clear(); sel.Clear();
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7770,16 +7839,19 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_ADDSELECTION: case SCI_ADDSELECTION:
sel.AddSelection(SelectionRange(static_cast<int>(wParam), static_cast<int>(lParam))); sel.AddSelection(SelectionRange(static_cast<int>(wParam), static_cast<int>(lParam)));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
case SCI_DROPSELECTIONN: case SCI_DROPSELECTIONN:
sel.DropSelection(static_cast<int>(wParam)); sel.DropSelection(static_cast<int>(wParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
case SCI_SETMAINSELECTION: case SCI_SETMAINSELECTION:
sel.SetMain(static_cast<int>(wParam)); sel.SetMain(static_cast<int>(wParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7788,6 +7860,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNCARET: case SCI_SETSELECTIONNCARET:
sel.Range(wParam).caret.SetPosition(static_cast<int>(lParam)); sel.Range(wParam).caret.SetPosition(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7796,6 +7869,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNANCHOR: case SCI_SETSELECTIONNANCHOR:
sel.Range(wParam).anchor.SetPosition(static_cast<int>(lParam)); sel.Range(wParam).anchor.SetPosition(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
case SCI_GETSELECTIONNANCHOR: case SCI_GETSELECTIONNANCHOR:
@ -7803,6 +7877,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNCARETVIRTUALSPACE: case SCI_SETSELECTIONNCARETVIRTUALSPACE:
sel.Range(wParam).caret.SetVirtualSpace(static_cast<int>(lParam)); sel.Range(wParam).caret.SetVirtualSpace(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7811,6 +7886,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNANCHORVIRTUALSPACE: case SCI_SETSELECTIONNANCHORVIRTUALSPACE:
sel.Range(wParam).anchor.SetVirtualSpace(static_cast<int>(lParam)); sel.Range(wParam).anchor.SetVirtualSpace(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7819,6 +7895,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNSTART: case SCI_SETSELECTIONNSTART:
sel.Range(wParam).anchor.SetPosition(static_cast<int>(lParam)); sel.Range(wParam).anchor.SetPosition(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;
@ -7827,6 +7904,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETSELECTIONNEND: case SCI_SETSELECTIONNEND:
sel.Range(wParam).caret.SetPosition(static_cast<int>(lParam)); sel.Range(wParam).caret.SetPosition(static_cast<int>(lParam));
ContainerNeedsUpdate(SC_UPDATE_SELECTION);
Redraw(); Redraw();
break; break;

View File

@ -234,6 +234,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
bool paintingAllText; bool paintingAllText;
bool willRedrawAll; bool willRedrawAll;
WorkNeeded workNeeded; WorkNeeded workNeeded;
int idleStyling;
bool needIdleStyling;
int modEventMask; int modEventMask;
@ -525,6 +527,10 @@ protected: // ScintillaBase subclass needs access to much of Editor
int PositionAfterArea(PRectangle rcArea) const; int PositionAfterArea(PRectangle rcArea) const;
void StyleToPositionInView(Position pos); void StyleToPositionInView(Position pos);
int PositionAfterMaxStyling(int posMax, bool scrolling) const;
void StartIdleStyling(bool truncatedLastStyling);
void StyleAreaBounded(PRectangle rcArea, bool scrolling);
void IdleStyling();
virtual void IdleWork(); virtual void IdleWork();
virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo=0); virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo=0);

View File

@ -410,8 +410,7 @@ const unsigned char *LineAnnotation::Styles(int line) const {
static char *AllocateAnnotation(int length, int style) { static char *AllocateAnnotation(int length, int style) {
size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);
char *ret = new char[len]; char *ret = new char[len]();
memset(ret, 0, len);
return ret; return ret;
} }

View File

@ -276,7 +276,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) {
} }
PRectangle rcac; PRectangle rcac;
rcac.left = pt.x - ac.lb->CaretFromEdge(); rcac.left = pt.x - ac.lb->CaretFromEdge();
if (pt.y >= rcPopupBounds.bottom - heightLB && // Wont fit below. if (pt.y >= rcPopupBounds.bottom - heightLB && // Won't fit below.
pt.y >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2) { // and there is more room above. pt.y >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2) { // and there is more room above.
rcac.top = pt.y - heightLB; rcac.top = pt.y - heightLB;
if (rcac.top < rcPopupBounds.top) { if (rcac.top < rcPopupBounds.top) {
@ -305,7 +305,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) {
// Make an allowance for large strings in list // Make an allowance for large strings in list
rcList.left = pt.x - ac.lb->CaretFromEdge(); rcList.left = pt.x - ac.lb->CaretFromEdge();
rcList.right = rcList.left + widthLB; rcList.right = rcList.left + widthLB;
if (((pt.y + vs.lineHeight) >= (rcPopupBounds.bottom - heightAlloced)) && // Wont fit below. if (((pt.y + vs.lineHeight) >= (rcPopupBounds.bottom - heightAlloced)) && // Won't fit below.
((pt.y + vs.lineHeight / 2) >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2)) { // and there is more room above. ((pt.y + vs.lineHeight / 2) >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2)) { // and there is more room above.
rcList.top = pt.y - heightAlloced; rcList.top = pt.y - heightAlloced;
} else { } else {

View File

@ -19,10 +19,6 @@ using namespace Scintilla;
namespace Scintilla { namespace Scintilla {
#endif #endif
enum { SURROGATE_TRAIL_FIRST = 0xDC00 };
enum { SURROGATE_TRAIL_LAST = 0xDFFF };
enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 };
unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen) { unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen) {
unsigned int len = 0; unsigned int len = 0;
for (unsigned int i = 0; i < tlen && uptr[i];) { for (unsigned int i = 0; i < tlen && uptr[i];) {

View File

@ -57,6 +57,10 @@ inline bool UTF8IsNEL(const unsigned char *us) {
enum { SURROGATE_LEAD_FIRST = 0xD800 }; enum { SURROGATE_LEAD_FIRST = 0xD800 };
enum { SURROGATE_LEAD_LAST = 0xDBFF }; enum { SURROGATE_LEAD_LAST = 0xDBFF };
enum { SURROGATE_TRAIL_FIRST = 0xDC00 };
enum { SURROGATE_TRAIL_LAST = 0xDFFF };
enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 };
inline unsigned int UTF16CharLength(wchar_t uch) { inline unsigned int UTF16CharLength(wchar_t uch) {
return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1; return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1;
} }

View File

@ -1 +1 @@
362 363