mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 15:56:48 +08:00
Fixed #557: Range returned by 'Expand selection' action doesn't get selected
This commit is contained in:
@@ -192,11 +192,11 @@ constructor(
|
||||
override fun onGlobalLayout() {
|
||||
val sheet = BottomSheetBehavior.from(this@EditorBottomSheet)
|
||||
val offset = view.height + SizeUtils.dp2px(1f)
|
||||
sheet.setFitToContents(false)
|
||||
sheet.setHalfExpandedRatio(0.3f)
|
||||
sheet.setGestureInsetBottomIgnored(false)
|
||||
sheet.setPeekHeight(binding.headerContainer.height)
|
||||
sheet.setExpandedOffset(offset)
|
||||
sheet.isFitToContents = false
|
||||
sheet.halfExpandedRatio = 0.3f
|
||||
sheet.isGestureInsetBottomIgnored = false
|
||||
sheet.peekHeight = binding.headerContainer.height
|
||||
sheet.expandedOffset = offset
|
||||
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,12 +248,14 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
*/
|
||||
@Override
|
||||
public void setSelection(@NonNull Range range) {
|
||||
if (isValidRange(range)) {
|
||||
if (isValidRange(range, true)) {
|
||||
setSelectionRegion(
|
||||
range.getStart().getLine(),
|
||||
range.getStart().getColumn(),
|
||||
range.getEnd().getLine(),
|
||||
range.getEnd().getColumn());
|
||||
} else {
|
||||
LOG.warn("Selection range is invalid", range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +342,7 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidRange(final Range range) {
|
||||
public boolean isValidRange(final Range range, boolean allowColumnEqual) {
|
||||
if (range == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -348,8 +350,8 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
final var start = range.getStart();
|
||||
final var end = range.getEnd();
|
||||
|
||||
return isValidPosition(start)
|
||||
&& isValidPosition(end)
|
||||
return isValidPosition(start, allowColumnEqual)
|
||||
&& isValidPosition(end, allowColumnEqual)
|
||||
&& start.compareTo(end) < 0; // make sure start position is before end position
|
||||
}
|
||||
|
||||
@@ -360,13 +362,13 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidPosition(final Position position) {
|
||||
public boolean isValidPosition(final Position position, boolean allowColumnEqual) {
|
||||
if (position == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isValidLine(position.getLine())
|
||||
&& isValidColumn(position.getLine(), position.getColumn());
|
||||
&& isValidColumn(position.getLine(), position.getColumn(), allowColumnEqual);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +381,7 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
public boolean isValidLine(int line) {
|
||||
return line >= 0 && line < getText().getLineCount();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given column is valid for this editor's text.
|
||||
*
|
||||
@@ -388,8 +390,9 @@ public class IDEEditor extends CodeEditor implements com.itsaky.androidide.edito
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidColumn(int line, int column) {
|
||||
return column >= 0 && column < getText().getColumnCount(line);
|
||||
public boolean isValidColumn(int line, int column, boolean allowEqual) {
|
||||
final var columnCount = getText().getColumnCount(line);
|
||||
return column >= 0 && (column < columnCount || (allowEqual && column == columnCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -102,7 +102,19 @@ public interface IEditor {
|
||||
* @param range The range to check.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
boolean isValidRange(Range range);
|
||||
default boolean isValidRange(Range range) {
|
||||
return isValidRange(range, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given range is valid for this editor's text.
|
||||
*
|
||||
* @param range The range to check.
|
||||
* @param allowColumnEqual Whether to allow <code>column</code> to be equal to column count of *
|
||||
* <code>line</code>.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
boolean isValidRange(Range range, boolean allowColumnEqual);
|
||||
|
||||
/**
|
||||
* Checks if the given position is valid for this editor's text.
|
||||
@@ -110,7 +122,19 @@ public interface IEditor {
|
||||
* @param position The position to check.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
boolean isValidPosition(Position position);
|
||||
default boolean isValidPosition(Position position) {
|
||||
return isValidPosition(position, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given position is valid for this editor's text.
|
||||
*
|
||||
* @param position The position to check.
|
||||
* @param allowColumnEqual Whether to allow <code>column</code> to be equal to column count of *
|
||||
* <code>line</code>.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
boolean isValidPosition(Position position, boolean allowColumnEqual);
|
||||
|
||||
/**
|
||||
* Checks if the given line is valid for this editor's text.
|
||||
@@ -126,8 +150,22 @@ public interface IEditor {
|
||||
* @param line The line of the column to check.
|
||||
* @param column The column to check.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
* @see #isValidColumn(int, int, boolean)
|
||||
*/
|
||||
boolean isValidColumn(int line, int column);
|
||||
default boolean isValidColumn(int line, int column) {
|
||||
return isValidColumn(line, column, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given column is valid for this editor's text.
|
||||
*
|
||||
* @param line The line of the column to check.
|
||||
* @param column The column to check.
|
||||
* @param allowColumnEqual Whether to allow <code>column</code> to be equal to column count of
|
||||
* <code>line</code>.
|
||||
* @return <code>true</code> if valid, <code>false</code> otherwise.
|
||||
*/
|
||||
boolean isValidColumn(int line, int column, boolean allowColumnEqual);
|
||||
|
||||
/**
|
||||
* Set the language server that this editor will connect with. If the language client is not set,
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user