Skip to content

Commit

Permalink
Simplify some FlagSet() codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 16, 2023
1 parent 33dfce6 commit 9de4a99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
10 changes: 2 additions & 8 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2266,17 +2266,11 @@ void DrawFoldLines(Surface *surface, const EditModel &model, const ViewStyle &vs
vsDraw.markers[static_cast<int>(MarkerOutline::Folder)].fore);
// Paint the line above the fold
// Paint the line above the fold
if ((subLine == 0) &&
((expanded && (FlagSet(model.foldFlags, FoldFlag::LineBeforeExpanded)))
||
(!expanded && (FlagSet(model.foldFlags, FoldFlag::LineBeforeContracted))))) {
if ((subLine == 0) && FlagSet(model.foldFlags, (expanded ? FoldFlag::LineBeforeContracted : FoldFlag::LineBeforeExpanded))) {
surface->FillRectangleAligned(Side(rcLine, Edge::top, 1.0), foldLineColour);
}
// Paint the line below the fold
if (lastSubLine &&
((expanded && (FlagSet(model.foldFlags, FoldFlag::LineAfterExpanded)))
||
(!expanded && (FlagSet(model.foldFlags, FoldFlag::LineAfterContracted))))) {
if (lastSubLine && FlagSet(model.foldFlags, (expanded ? FoldFlag::LineAfterExpanded : FoldFlag::LineAfterContracted))) {
surface->FillRectangleAligned(Side(rcLine, Edge::bottom, 1.0), foldLineColour);
// If contracted fold line drawn then don't overwrite with hidden line
// as fold lines are more specific then hidden lines.
Expand Down
17 changes: 8 additions & 9 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ constexpr bool CanEliminate(const DocModification &mh) noexcept {
in a [possibly lengthy] multi-step Undo/Redo sequence
*/
constexpr bool IsLastStep(const DocModification &mh) noexcept {
return
FlagSet(mh.modificationType, (ModificationFlags::Undo | ModificationFlags::Redo))
&& FlagSet(mh.modificationType, ModificationFlags::MultiStepUndoRedo)
&& FlagSet(mh.modificationType, ModificationFlags::LastStepInUndoRedo)
&& FlagSet(mh.modificationType, ModificationFlags::MultilineUndoRedo);
constexpr ModificationFlags finalMask = ModificationFlags::MultiStepUndoRedo
| ModificationFlags::LastStepInUndoRedo
| ModificationFlags::MultilineUndoRedo;
return FlagSet(mh.modificationType, (ModificationFlags::Undo | ModificationFlags::Redo))
&& ((mh.modificationType & finalMask) == finalMask);
}

}
Expand Down Expand Up @@ -2755,7 +2755,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) {
if (FlagSet(mh.modificationType, ModificationFlags::BeforeInsert)) {
if (pdoc->ContainsLineEnd(mh.text, mh.length) && (mh.position != pdoc->LineStart(lineOfPos)))
endNeedShown = pdoc->LineStart(lineOfPos + 1);
} else if (FlagSet(mh.modificationType, ModificationFlags::BeforeDelete)) {
} else {
// If the deletion includes any EOL then we extend the need shown area.
endNeedShown = mh.position + mh.length;
Sci::Line lineLast = pdoc->SciLineFromPosition(mh.position + mh.length);
Expand Down Expand Up @@ -2830,7 +2830,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) {
SetScrollBars();
}

if ((FlagSet(mh.modificationType, ModificationFlags::ChangeMarker)) || (FlagSet(mh.modificationType, ModificationFlags::ChangeMargin))) {
if (FlagSet(mh.modificationType, (ModificationFlags::ChangeMarker | ModificationFlags::ChangeMargin))) {
if ((!willRedrawAll) && ((paintState == PaintState::notPainting) || !PaintContainsMargin())) {
if (FlagSet(mh.modificationType, ModificationFlags::ChangeFold)) {
// Fold changes can affect the drawing of following lines so redraw whole margin
Expand Down Expand Up @@ -4632,8 +4632,7 @@ void Editor::MouseLeave() {
}

static constexpr bool AllowVirtualSpace(VirtualSpace virtualSpaceOptions, bool rectangular) noexcept {
return (!rectangular && (FlagSet(virtualSpaceOptions, VirtualSpace::UserAccessible)))
|| (rectangular && (FlagSet(virtualSpaceOptions, VirtualSpace::RectangularSelection)));
return FlagSet(virtualSpaceOptions, (rectangular ? VirtualSpace::RectangularSelection : VirtualSpace::UserAccessible));
}

void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modifiers) {
Expand Down
3 changes: 1 addition & 2 deletions scintilla/src/ViewStyle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ bool ViewStyle::SetWrapIndentMode(WrapIndentMode wrapIndentMode_) noexcept {

bool ViewStyle::IsBlockCaretStyle() const noexcept {
return ((caret.style & CaretStyle::InsMask) == CaretStyle::Block) ||
FlagSet(caret.style, CaretStyle::OverstrikeBlock) ||
FlagSet(caret.style, CaretStyle::Curses);
FlagSet(caret.style, (CaretStyle::OverstrikeBlock | CaretStyle::Curses));
}

bool ViewStyle::IsCaretVisible(bool isMainSelection) const noexcept {
Expand Down

0 comments on commit 9de4a99

Please sign in to comment.