Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
guard experimental "incremental" ast parser feature with kconf flag "…
Browse files Browse the repository at this point in the history
…experimental/astparser/incremental"
  • Loading branch information
rsms committed Apr 23, 2011
1 parent eef8bcb commit dbaafbb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AST.mm
Expand Up @@ -54,7 +54,7 @@

bool AST::parseEdit(NSUInteger changeLocation, long changeDelta) {
// if a full parse is needed, take the "quick" route
if (needFullParse_)
if (needFullParse_ || changeLocation == NSNotFound)
return parse();

// bail unless we have a valid grammar
Expand Down
25 changes: 17 additions & 8 deletions src/KDocument.mm
Expand Up @@ -1351,7 +1351,7 @@ - (void)_updateLinesToRangesInfoForTextStorage:(NSTextStorage*)textStorage

// invoked after an editing occured, but before it's been committed
// Has the nasty side effect of losing the selection if applying attributes
- (void)textStorageWillProcessEditing:(NSNotification *)notification {
/*- (void)textStorageWillProcessEditing:(NSNotification *)notification {
NSTextStorage *textStorage = [notification object];
if (!(textStorage.editedMask & NSTextStorageEditedCharacters))
Expand All @@ -1363,7 +1363,7 @@ - (void)textStorageWillProcessEditing:(NSNotification *)notification {
// parse edit
ast_->parseEdit(editedRange.location, changeDelta);
}
}*/


// invoked after an editing occured which has just been committed
Expand All @@ -1386,19 +1386,28 @@ - (void)textStorageDidProcessEditing:(NSNotification *)notification {
NSRange editedRange = [textStorage editedRange];

// length delta of the edit (i.e. negative for deletions)
int changeInLength = [textStorage changeInLength];
NSInteger changeDelta = [textStorage changeInLength];

// parse edit and apply style
if (kconf_bool(@"astparser/enabled", YES)) {
if (kconf_bool(@"experimental/astparser/incremental", NO)) {
ast_->parseEdit(editedRange.location, changeDelta);
} else {
ast_->parseEdit(NSNotFound, 0);
}
}

// update lineToRangeVec_ (need to run in main)
if ([NSThread isMainThread]) {
[self _updateLinesToRangesInfoForTextStorage:textStorage
inRange:editedRange
changeDelta:changeInLength
changeDelta:changeDelta
recursed:NO];
} else {
K_DISPATCH_MAIN_ASYNC({
[self _updateLinesToRangesInfoForTextStorage:textStorage
inRange:editedRange
changeDelta:changeInLength
changeDelta:changeDelta
recursed:NO];
});
}
Expand All @@ -1414,7 +1423,7 @@ - (void)textStorageDidProcessEditing:(NSNotification *)notification {
v8::String::New("edit"),
v8::Number::New((double)version),
v8::Number::New((double)editedRange.location),
v8::Integer::New(changeInLength)
v8::Integer::New(changeDelta)
};
static const int argc = sizeof(argv) / sizeof(argv[0]);
v8::TryCatch tryCatch;
Expand Down Expand Up @@ -1442,8 +1451,8 @@ - (void)textStorageDidProcessEditing:(NSNotification *)notification {
DLOG_RANGE(editedRange, textStorage.string);
#endif

DLOG("editedRange: %@, changeInLength: %d, wasInUndoRedo: %@, editedMask: %d",
NSStringFromRange(editedRange), changeInLength,
DLOG("editedRange: %@, changeDelta: %d, wasInUndoRedo: %@, editedMask: %d",
NSStringFromRange(editedRange), changeDelta,
wasInUndoRedo ? @"YES":@"NO", textStorage.editedMask);

#if 0
Expand Down

0 comments on commit dbaafbb

Please sign in to comment.