From 0657ead6a52e45b872fc1819e28022aadd174fe2 Mon Sep 17 00:00:00 2001 From: Nebojsa Vuksic Date: Fri, 1 Aug 2025 11:25:17 +0200 Subject: [PATCH] Remove unnecessary Column usage --- .../components/SearchBarWithAutoCompletion.kt | 103 +++++++++--------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/plugins/template/components/SearchBarWithAutoCompletion.kt b/src/main/kotlin/org/jetbrains/plugins/template/components/SearchBarWithAutoCompletion.kt index b623655..9afaea4 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/components/SearchBarWithAutoCompletion.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/components/SearchBarWithAutoCompletion.kt @@ -51,63 +51,60 @@ internal fun SearchBarWithAutoCompletion( .collect { searchTerm -> popupController.onQueryChanged(searchTerm) } } - Column(modifier = modifier) { - Box( + Box( + modifier = modifier + .padding(8.dp) + ) { + var textFieldWidth by remember { mutableIntStateOf(-1) } + TextField( + state = textFieldState, modifier = Modifier + .onGloballyPositioned { coordinates -> textFieldWidth = coordinates.size.width } .fillMaxWidth() - .padding(8.dp) - ) { - var textFieldWidth by remember { mutableIntStateOf(-1) } - TextField( - state = textFieldState, - modifier = Modifier - .onGloballyPositioned { coordinates -> textFieldWidth = coordinates.size.width } - .fillMaxWidth() - .handlePopupCompletionKeyEvents(popupController) { item -> - textFieldState.setTextAndPlaceCursorAtEnd(item.label) - onSelectCompletion(item) + .handlePopupCompletionKeyEvents(popupController) { item -> + textFieldState.setTextAndPlaceCursorAtEnd(item.label) + onSelectCompletion(item) + } + .focusRequester(focusRequester), + placeholder = { Text(searchFieldPlaceholder) }, + leadingIcon = { + Icon(AllIconsKeys.Actions.Find, contentDescription = "Find icon", Modifier.padding(end = 8.dp)) + }, + trailingIcon = { + if (textFieldState.text.isNotBlank()) { + CloseIconButton { + onClear() + textFieldState.setTextAndPlaceCursorAtEnd("") } - .focusRequester(focusRequester), - placeholder = { Text(searchFieldPlaceholder) }, - leadingIcon = { - Icon(AllIconsKeys.Actions.Find, contentDescription = "Find icon", Modifier.padding(end = 8.dp)) - }, - trailingIcon = { - if (textFieldState.text.isNotBlank()) { - CloseIconButton { - onClear() - textFieldState.setTextAndPlaceCursorAtEnd("") - } - } - }, - ) + } + }, + ) - if (popupController.isVisible) { - PopupMenu( - onDismissRequest = { - popupController.reset() - true - }, - horizontalAlignment = Alignment.Start, - modifier = Modifier - // Aligns PopupMenu with TextField - .width(with(LocalDensity.current) { textFieldWidth.toDp() }) - .wrapContentHeight() - .padding(vertical = 4.dp, horizontal = 2.dp) - .zIndex(5f), - popupProperties = PopupProperties(focusable = false), - ) { - popupController.filteredItems.forEach { item -> - selectableItem( - popupController. isItemSelected(item), - onClick = { - onSelectCompletion(item) - popupController.onItemAutocompleteConfirmed() - textFieldState.setTextAndPlaceCursorAtEnd(item.label) - }, - ) { - Text(item.label) - } + if (popupController.isVisible) { + PopupMenu( + onDismissRequest = { + popupController.reset() + true + }, + horizontalAlignment = Alignment.Start, + modifier = Modifier + // Aligns PopupMenu with TextField + .width(with(LocalDensity.current) { textFieldWidth.toDp() }) + .wrapContentHeight() + .padding(vertical = 4.dp, horizontal = 2.dp) + .zIndex(5f), + popupProperties = PopupProperties(focusable = false), + ) { + popupController.filteredItems.forEach { item -> + selectableItem( + popupController.isItemSelected(item), + onClick = { + onSelectCompletion(item) + popupController.onItemAutocompleteConfirmed() + textFieldState.setTextAndPlaceCursorAtEnd(item.label) + }, + ) { + Text(item.label) } } }