Skip to content

Commit

Permalink
G5V8DT-25849 Нет переноса строки при создании новой области в модуле
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Kuznetsov committed Oct 23, 2024
1 parent 2300477 commit af7a666
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@
public class BslModuleRegionsInfo
implements IBslModuleTextInsertInfo
{
/**
* Has region before offset position
*/
public static final int REGION_FLAG_HAS_REGION_BEFORE = 1;

/**
* Has region after offset position
*/
public static final int REGION_FLAG_HAS_REGION_AFTER = 2;

private final URI resourceURI;
private final int insertPosition;
private final int clearPosition;
private final int clearLength;
private final int regionFlags;
private final String regionName;

/**
Expand All @@ -37,15 +48,17 @@ public class BslModuleRegionsInfo
* @param insertPosition <code>int</code> insertion offset, cannot be negative
* @param clearPosition text clear <code>int</code> position, can be negative if no clear needed
* @param clearLength text clear <code>int</code> length, can be negative if no clear needed
* @param regionFlags region <code>int</code> flags represents regions states, cannot be negative
* @param regionName {@link String} region name, can be <code>null</code>
*/
public BslModuleRegionsInfo(URI resourceURI, int insertPosition, int clearPosition, int clearLength,
String regionName)
int regionFlags, String regionName)
{
this.resourceURI = resourceURI;
this.insertPosition = insertPosition;
this.clearPosition = clearPosition;
this.clearLength = clearLength;
this.regionFlags = regionFlags;
this.regionName = regionName;
}

Expand All @@ -67,6 +80,16 @@ public int getClearLength()
return clearLength;
}

/**
* Returns flags which represents regions states
*
* @return <code>int</code> flags, cannot be negative
*/
public int getRegionFlags()
{
return regionFlags;
}

/**
* Returns region name
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument doc
{
regionName = suffix.isEmpty() ? declaredRegionName : (declaredRegionName + suffix);
}
return new BslModuleRegionsInfo(resourceURI, offset, clearOffset, clearLength, regionName);
int flags = calculateFlags(project, regionOffsets, offset);
return new BslModuleRegionsInfo(resourceURI, offset, clearOffset, clearLength, flags, regionName);
}

@Override
Expand All @@ -129,14 +130,19 @@ public String wrap(IBslModuleTextInsertInfo moduleTextInsertInfo, String content
String endRegion = proposals.getEndRegionPropStr();
String space = proposals.getSpacePropStr();
StringBuilder builder = new StringBuilder();
int flags = moduleRegionInformation.getRegionFlags();
boolean hasRegionBefore = (flags
& BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_BEFORE) == BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_BEFORE;
boolean hasRegionAfter = (flags
& BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_AFTER) == BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_AFTER;
if (moduleTextInsertInfo.getPosition() != 0)
{
builder.append(lineSeparator);
}
builder.append(beginRegion).append(space).append(regionName);
builder.append(content);
builder.append(endRegion);
if (moduleTextInsertInfo.getPosition() == 0)
if (moduleTextInsertInfo.getPosition() == 0 || (hasRegionAfter && !hasRegionBefore))
{
builder.append(lineSeparator);
}
Expand Down Expand Up @@ -240,6 +246,23 @@ else if (createNewRegion)
return offset;
}

private int calculateFlags(IV8Project project, Map<String, BslModuleOffsets> regionOffsets, int offset)
{
int flags = 0;
for (BslModuleOffsets offsets : regionOffsets.values())
{
if (offsets.getEndOffset() <= offset)
{
flags |= BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_BEFORE;
}
if (offsets.getStartOffset() >= offset)
{
flags |= BslModuleRegionsInfo.REGION_FLAG_HAS_REGION_AFTER;
}
}
return flags;
}

private boolean isRegionExists(Map<String, BslModuleOffsets> regionOffsets, String declaredRegionName,
String suffix)
{
Expand Down

0 comments on commit af7a666

Please sign in to comment.