Skip to content

Commit

Permalink
feat: inline documentation (first pass)
Browse files Browse the repository at this point in the history
see #76 #76
  • Loading branch information
ianatha committed Nov 11, 2023
1 parent e253540 commit 8c10dd6
Show file tree
Hide file tree
Showing 16 changed files with 11,695 additions and 13 deletions.
39 changes: 38 additions & 1 deletion app/src/main/java/io/atha/bababasic/ActivityMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.atha.bababasic.databinding.ActivityMainBinding
import io.atha.bababasic.editor.switchThemeIfRequired
import io.atha.libbababasic.Interpreter.checkSyntax
import io.atha.libbababasic.error.SyntaxError
import io.atha.libbababasic.runtime.helpFor
import io.github.rosemoe.sora.event.ContentChangeEvent
import io.github.rosemoe.sora.event.EditorKeyEvent
import io.github.rosemoe.sora.event.KeyBindingEvent
Expand Down Expand Up @@ -325,6 +326,21 @@ class ActivityMain : AppCompatActivity() {

private fun updatePositionText() {
val cursor = binding.editor.cursor
val word = getClosestWord(binding.editor.text.toString(), cursor.left)
val help = helpFor(word)
if (help == null) {
if (word == null) {
binding.helpView.text = "No help found"
} else {
binding.helpView.text = "No help found for $word"
}
} else {
binding.helpView.text = help
}
return



var text =
(1 + cursor.leftLine).toString() + ":" + cursor.leftColumn + ";" + cursor.left + " "
text += if (cursor.isSelected) {
Expand Down Expand Up @@ -492,6 +508,14 @@ class ActivityMain : AppCompatActivity() {
val id = item.itemId
val editor = binding.editor
when (id) {
R.id.show_help -> {
if (binding.helpView.visibility == View.VISIBLE) {
binding.helpView.visibility = View.GONE
} else {
binding.helpView.visibility = View.VISIBLE
}
}

R.id.open_file -> {
firebaseAnalytics.logEvent("open", null)
val intent = Intent()
Expand Down Expand Up @@ -633,4 +657,17 @@ class ActivityMain : AppCompatActivity() {
e.printStackTrace()
}
}
}
}


val separators = listOf(" ", "\n", "\t")
fun getClosestWord(text: String, cursorPosition: Int): String? {
if (cursorPosition !in text.indices) {
return null // Cursor position is out of bounds
}
val start = text.substring(0, cursorPosition).lastIndexOfAny(separators) + 1
val end = text.indexOfAny(separators, cursorPosition).takeIf { it != -1 } ?: text.length

return text.substring(start, end)
}

11 changes: 11 additions & 0 deletions app/src/main/res/drawable/help.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M478,720Q499,720 513.5,705.5Q528,691 528,670Q528,649 513.5,634.5Q499,620 478,620Q457,620 442.5,634.5Q428,649 428,670Q428,691 442.5,705.5Q457,720 478,720ZM442,566L516,566Q516,533 523.5,514Q531,495 566,462Q592,436 607,412.5Q622,389 622,356Q622,300 581,270Q540,240 484,240Q427,240 391.5,270Q356,300 342,342L408,368Q413,350 430.5,329Q448,308 484,308Q516,308 532,325.5Q548,343 548,364Q548,384 536,401.5Q524,419 506,434Q462,473 452,493Q442,513 442,566ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
</vector>
48 changes: 36 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
android:id="@+id/editor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"

android:scrollbarThumbHorizontal="@drawable/scrollbar_thumb"
android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
android:scrollbarTrackHorizontal="@drawable/scrollbar_track"
Expand All @@ -123,25 +123,49 @@
app:lnPanelPositionMode="follow" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="-40dp"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="-40dp"
android:orientation="vertical">

<HorizontalScrollView
android:contentDescription="@string/symbol_keyboard"
android:layout_width="match_parent"
android:layout_height="40dp"
tools:ignore="UselessParent">
android:contentDescription="@string/symbol_keyboard"
android:layout_width="match_parent"
android:layout_height="40dp"
tools:ignore="UselessParent">

<io.github.rosemoe.sora.widget.SymbolInputView
android:id="@+id/symbol_input"
android:layout_width="wrap_content"
android:layout_height="40dp" />
android:id="@+id/symbol_input"
android:layout_width="wrap_content"
android:layout_height="40dp" />

</HorizontalScrollView>


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="-160dp"
android:orientation="vertical">
<ScrollView
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="160dp">
<TextView
android:id="@+id/help_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_400"
android:fontFamily="monospace"
android:paddingHorizontal="8dp"
android:textSize="14dp"
android:text=""
android:textColor="@color/black"
android:visibility="gone" />
</ScrollView>
</LinearLayout>


</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
android:title="@string/run"
app:showAsAction="always" />

<item
android:id="@+id/show_help"
android:icon="@drawable/help"
android:title="@string/show_help"
app:showAsAction="always" />

<item
android:id="@+id/text_undo"
android:icon="@drawable/undo"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="close">Schließen</string>
<string name="examples">Beispiele</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
<string name="close">Κλείσιμο</string>
<string name="examples">Παραδείγματα</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="close">Close</string>
<string name="examples">Ejemplos</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
<string name="close">Close</string>
<string name="examples">Exemples</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="close">Close</string>
<string name="examples">Esempi</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="close">Close</string>
<string name="examples">例</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="close">Close</string>
<string name="examples">Exemplos</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
<string name="close">Close</string>
<string name="examples">Examples</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="show_help">Show Help</string>
</resources>
1 change: 1 addition & 0 deletions libbababasic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
antlr("org.antlr:antlr4:4.13.1")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("io.github.classgraph:classgraph:4.8.164")
implementation("org.antlr:antlr4-runtime:4.13.1")
implementation("com.google.guava:guava:29.0-jre")
implementation("org.apache.commons:commons-csv:1.7")
Expand Down
Loading

0 comments on commit 8c10dd6

Please sign in to comment.