Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 26, 2025

Problem

On iOS 18+, the TextArea.NON_PREDICTIVE flag was completely ignored for multiline TextArea components, causing predictive text and inline suggestions to appear even when explicitly disabled. This led to cursor misplacement issues when iOS's "Show Predictions Inline" feature was enabled, making multiline text input frustrating and unreliable.

The issue only affected multiline TextArea components - single-line TextField components worked correctly.

Root Cause

The iOS native implementation in CodenameOne_GLViewController.m only applied text input constraints (including NON_PREDICTIVE) to single-line text fields (CN1UITextField). The multiline text view code path (CN1UITextView) completely lacked constraint handling, causing all flags like NON_PREDICTIVE, INITIAL_CAPS_WORD, etc. to be ignored.

Solution

Added comprehensive constraint handling to the multiline text view creation in Java_com_codename1_impl_ios_IOSImplementation_editStringAtImpl:

  • NON_PREDICTIVE (0x80000): Sets autocorrectionType = UITextAutocorrectionTypeNo to disable predictive text
  • Capitalization constraints: INITIAL_CAPS_WORD, INITIAL_CAPS_SENTENCE, UPPERCASE
  • Security constraints: PASSWORD, USERNAME with proper textContentType
  • Keyboard types: EMAILADDR, NUMERIC, PHONENUMBER, URL, DECIMAL

The implementation mirrors the existing single-line constraint logic, ensuring consistent behavior across both text input types.

Testing

The fix resolves the exact scenario described in the bug report:

// These now properly disable predictive text on iOS
TextComponent multiLine = new TextComponent().multiline(true).label("Multi line");
multiLine.getField().setConstraint(TextArea.NON_PREDICTIVE);

TextArea simpleMultiLine = new TextArea();
simpleMultiLine.setConstraint(TextArea.NON_PREDICTIVE);

Impact

  • ✅ Fixes cursor misplacement issues on iOS 18+ with inline predictions
  • ✅ Ensures cross-platform consistency (iOS now matches Android behavior)
  • ✅ Maintains backward compatibility with no breaking changes
  • ✅ Enables all text constraints to work properly on multiline TextArea components

Closes the issue where multiline TextArea components ignored the NON_PREDICTIVE flag, causing poor user experience on modern iOS devices.

Original prompt

This section details on the original issue you should resolve

<issue_title>TextArea - iOS - Non predictive flag ignored on multiline TextArea and carret misplaced due to inline predictions</issue_title>
<issue_description>Describe the bug
On iOS 18+, when typing in a multiline TextArea with "Predictive Text" and "Show Predictions Inline" enabled (default settings), the carret is misplaced when the prediction is shown in the field and we continue typing what's predicted.
This happen only on multiline TextArea, never with simple TextField or mono line TextArea.
Of course same is happening with a multiline TextComponent.

The flag TextArea.NON_PREDICTIVE doesn't do anything in multiline.

To Reproduce
Steps to reproduce the behavior:

  1. Create a barebone project and copy the attached minimal code.
  2. Configure the device with "Predictive Text" and "Show Predictions Inline" enabled. (General > Keyboard)
  3. Type any text in the two last textboxes. This need to be real text, so the predictions will show up.
  4. Once a prediciton is shown inline, type the first predicted char, the rest of the prediction autovalidate itself and the carret is in the middle of the word, which is at least annoying.

Expected behavior
Working flag TextArea.NON_PREDICTIVE.
Carret at the end of the word or prediction not becoming true text like that, last one should be better

Screenshots

Image

Desktop (please complete the following information):
NA

Smartphone (please complete the following information):

  • Device: Ipad 8
  • OS: iPadOS 18.4.1
  • Version 7.0.204

Minimal code to reproduce

    public void runApp() {
        Form hi = new Form("Predictive Carret failure", BoxLayout.y());
        Button revalidateBtn = new Button("Grow - Shrink");
        hi.add(revalidateBtn);
        TextComponent singleLine = new TextComponent().label("Single line");
        singleLine.getField().setConstraint(TextArea.NON_PREDICTIVE);
        hi.add(singleLine);
        TextComponent multiLine = new TextComponent().multiline(true).label("Multi line");
        multiLine.getField().setConstraint(TextArea.NON_PREDICTIVE);
        hi.add(multiLine);
        TextArea simpleMultiLine = new TextArea();
        simpleMultiLine.setConstraint(TextArea.NON_PREDICTIVE);
        hi.add("Simple Multi Line");
        hi.add(simpleMultiLine);
        revalidateBtn.addActionListener(e -> {
            hi.forceRevalidate();
            singleLine.growShrink(1000);
            multiLine.growShrink(1000);
            simpleMultiLine.growShrink(1000);
        });
        hi.show();
    }
````</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #3941

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] TextArea - iOS - Non predictive flag ignored on multiline TextArea and carret misplaced due to inline predictions Fix iOS multiline TextArea NON_PREDICTIVE constraint ignored causing cursor misplacement Sep 26, 2025
Copilot AI requested a review from shannah September 26, 2025 02:27
@shannah shannah marked this pull request as ready for review September 27, 2025 01:07
@shannah
Copy link
Collaborator

shannah commented Sep 27, 2025

Tested on iOS device. This fixes the issue with non-predictive not being respected on TextAreas in iOS.

@shannah shannah merged commit a935bef into master Sep 27, 2025
1 check passed
@shannah shannah deleted the copilot/fix-6ab70d29-92d9-4866-afe3-8def78fc3af5 branch September 27, 2025 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextArea - iOS - Non predictive flag ignored on multiline TextArea and carret misplaced due to inline predictions

2 participants