Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Fix inline R bug, fix R var references on load

AuthorDaveJarvis <email>
Date2023-07-03 22:15:23 GMT-0700
Commita0ec1ee69e66073f3c98409b40cd0d618ba2e003
Parentff672a7
Delta13 lines added, 9 lines removed, 4-line increase
src/main/java/com/keenwrite/ui/fonts/IconFactory.java
}
else {
- final var mediaType = MediaType.valueFrom( path );
+ final var mediaType = MediaType.fromFilename( path );
final var mte = MediaTypeExtension.valueFrom( mediaType );
src/main/java/com/keenwrite/processors/r/RBootstrapController.java
private final Workspace mWorkspace;
- private final Supplier<Map<String, String>> mDefinitions;
+ private final Supplier<Map<String, String>> mSupplier;
public RBootstrapController(
final Workspace workspace,
final Supplier<Map<String, String>> supplier ) {
+ assert workspace != null;
+ assert supplier != null;
+
mWorkspace = workspace;
- mDefinitions = supplier;
+ mSupplier = supplier;
mWorkspace.stringProperty( KEY_R_SCRIPT )
.addListener( ( c, o, n ) -> update() );
mWorkspace.fileProperty( KEY_R_DIR )
.addListener( ( c, o, n ) -> update() );
+
+ // Add the definitions immediately upon loading them.
+ update();
}
if( !bootstrap.isBlank() ) {
final var dir = getRWorkingDirectory();
- final var definitions = mDefinitions.get();
+ final var definitions = mSupplier.get();
- // A problem with the bootstrap script is likely caused by variables
- // not being loaded. This implies that the R processor is being invoked
- // too soon.
update( bootstrap, dir, definitions );
}
src/main/java/com/keenwrite/processors/r/RInlineEvaluator.java
int index = 0;
int began;
- int ended;
+ int ended = 0;
- while( (began = text.indexOf( PREFIX, index )) >= 0 ) {
+ while( (began = text.indexOf( PREFIX, index )) >= 0 && ended > -1 ) {
buffer.append( text, index, began );
+ // If the R expression has no definite end, this returns -1.
ended = text.indexOf( SUFFIX, began + 1 );