Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
jsedit.cpp File Reference
#include "jsedit.h"
Include dependency graph for jsedit.cpp:

Go to the source code of this file.

Classes

struct  BlockInfo
 
class  SidebarWidget
 
class  JSDocLayout
 
class  JSEditPrivate
 

Functions

 Q_DECLARE_TYPEINFO (BlockInfo, Q_PRIMITIVE_TYPE)
 
static int findClosingMatch (const QTextDocument *doc, int cursorPosition)
 
static int findOpeningMatch (const QTextDocument *doc, int cursorPosition)
 
static int findClosingConstruct (const QTextBlock &block)
 

Function Documentation

◆ findClosingConstruct()

static int findClosingConstruct ( const QTextBlock &  block)
static

Definition at line 754 of file jsedit.cpp.

755 {
756  if (!block.isValid())
757  return -1;
758  JSBlockData *blockData = reinterpret_cast<JSBlockData*>(block.userData());
759  if (!blockData)
760  return -1;
761  if (blockData->bracketPositions.isEmpty())
762  return -1;
763  const QTextDocument *doc = block.document();
764  int offset = block.position();
765  foreach (int pos, blockData->bracketPositions) {
766  int absPos = offset + pos;
767  if (doc->characterAt(absPos) == '{') {
768  int matchPos = findClosingMatch(doc, absPos);
769  if (matchPos >= 0)
770  return matchPos;
771  }
772  }
773  return -1;
774 }

References JSBlockData::bracketPositions, and findClosingMatch().

Referenced by JSEdit::fold(), JSEdit::isFoldable(), and JSEdit::unfold().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findClosingMatch()

static int findClosingMatch ( const QTextDocument *  doc,
int  cursorPosition 
)
static

Definition at line 534 of file jsedit.cpp.

535 {
536  QTextBlock block = doc->findBlock(cursorPosition);
537  JSBlockData *blockData = reinterpret_cast<JSBlockData*>(block.userData());
538  if (!blockData->bracketPositions.isEmpty()) {
539  int depth = 1;
540  while (block.isValid()) {
541  blockData = reinterpret_cast<JSBlockData*>(block.userData());
542  if (blockData && !blockData->bracketPositions.isEmpty()) {
543  for (int c = 0; c < blockData->bracketPositions.count(); ++c) {
544  int absPos = block.position() + blockData->bracketPositions.at(c);
545  if (absPos <= cursorPosition)
546  continue;
547  if (doc->characterAt(absPos) == '{')
548  depth++;
549  else
550  depth--;
551  if (depth == 0)
552  return absPos;
553  }
554  }
555  block = block.next();
556  }
557  }
558  return -1;
559 }

References JSBlockData::bracketPositions.

Referenced by findClosingConstruct(), and JSEdit::updateCursor().

Here is the caller graph for this function:

◆ findOpeningMatch()

static int findOpeningMatch ( const QTextDocument *  doc,
int  cursorPosition 
)
static

Definition at line 561 of file jsedit.cpp.

562 {
563  QTextBlock block = doc->findBlock(cursorPosition);
564  JSBlockData *blockData = reinterpret_cast<JSBlockData*>(block.userData());
565  if (!blockData->bracketPositions.isEmpty()) {
566  int depth = 1;
567  while (block.isValid()) {
568  blockData = reinterpret_cast<JSBlockData*>(block.userData());
569  if (blockData && !blockData->bracketPositions.isEmpty()) {
570  for (int c = blockData->bracketPositions.count() - 1; c >= 0; --c) {
571  int absPos = block.position() + blockData->bracketPositions.at(c);
572  if (absPos >= cursorPosition - 1)
573  continue;
574  if (doc->characterAt(absPos) == '}')
575  depth++;
576  else
577  depth--;
578  if (depth == 0)
579  return absPos;
580  }
581  }
582  block = block.previous();
583  }
584  }
585  return -1;
586 }

References JSBlockData::bracketPositions.

Referenced by JSEdit::updateCursor().

Here is the caller graph for this function:

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( BlockInfo  ,
Q_PRIMITIVE_TYPE   
)
JSBlockData
Definition: jsedit.h:42
JSBlockData::bracketPositions
QList< int > bracketPositions
Definition: jsedit.h:45
findClosingMatch
static int findClosingMatch(const QTextDocument *doc, int cursorPosition)
Definition: jsedit.cpp:534