Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-177 Link cut and copy to new buttons #4888

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,8 @@ public void setSelectionToFirstParamOfRegularExpressionAtInternalIndex(int index
internFormula.setSelectionToFirstParamOfRegularExpressionAtInternalIndex(indexOfRegularExpression);
highlightSelection();
}

public InternFormula getInternFormula() {
return internFormula;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -1182,4 +1182,8 @@ public boolean isThereSomethingToDelete() {
public void setInternTokenFormulaList(List<InternToken> list) {
internTokenFormulaList = list;
}

public List<InternToken> getInternTokenFormulaList() {
return internTokenFormulaList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class FormulaEditorClipboard(private val formulaEditorEditText: FormulaEditorEdi
copyTokens(formulaEditorEditText.selectedTokens)
}

fun checkIfSelectedAndCopy() {
if (formulaEditorEditText.selectedTokens != null) {
copyTokens(formulaEditorEditText.selectedTokens)
} else {
copyTokens(formulaEditorEditText.internFormula.internTokenFormulaList)
}
}

fun paste() {
clipboard?.let { formulaEditorEditText.addTokens(cloneTokens(it)); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public boolean onTouch(View view, MotionEvent event) {
formulaEditorClipboard.paste();
return true;
case R.id.formula_editor_keyboard_copy:
formulaEditorClipboard.copy();
formulaEditorClipboard.checkIfSelectedAndCopy();
return true;
default:
formulaEditorEditText.handleKeyEvent(view.getId(), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ class FormulaEditorClipboardTest {
assertNull(controller.clipboard)
}

@Test
fun shouldCopyWholeContent() {
val token = InternToken(InternTokenType.NUMBER, "12345678")
val tokens = listOf(token)
`when`(formulaEditorEditText.selectedTokens).thenReturn(tokens)
controller.checkIfSelectedAndCopy()
controller.clipboard?.let { clipboardIt ->
assertSameValuesButDifferentObjects(tokens, clipboardIt)
}
}

@Test
fun shouldCopySelectedPart() {
val token1 = InternToken(InternTokenType.NUMBER, "1234")
val token2 = InternToken(InternTokenType.OPERATOR, "+")
val token3 = InternToken(InternTokenType.NUMBER, "5678")
val tokens = listOf(token1, token2, token3)
formulaEditorEditText.addTokens(tokens)
`when`(formulaEditorEditText.selectedTokens).thenReturn(listOf(token1))
controller.checkIfSelectedAndCopy()
controller.clipboard?.let { clipboardIt ->
assertSameValuesButDifferentObjects(listOf(token1), clipboardIt)
}
}

@Test
fun shouldPaste() {
val token1 = InternToken(InternTokenType.FUNCTION_NAME, "TestFunctionName")
Expand Down