JTextPane, second word must not go to new line when typing and exceeding width - jtextpane

I'm using JTextPane because I need to markup text.
When typing into the JtextPane the second word always goes to new line. Then also when making the second word longer (after it went to a new line) the scroll bar appears and the JTextPane resizes. If I start typing in a new row then second word in that line does not go to a new line (as long the second word does not exceed width)
I tried adding a blank string that is very long in the first line and seems to do the trick, but this blank line is not really what I want to have.
Also tried adding it to after the text but it gives more problems
Is there something else that I can do to make the text only go to new line when I press enter? I can do it without a blank string using jtextarea, but then I can't markup text as I type.

I found the answer:
JTextPane textPane = new JTextPane()
{
public boolean getScrollableTracksViewportWidth()
{
return getUI().getPreferredSize(this).width
<= getParent().getSize().width;
}
};
We can overite the getScrollableTracksViewportWidth method to have a no wrapping text pane.
Website for more info: Here

Related

Sublime Text selection issue

In my Sublime Text (v3), there seems to be some issue suddenly with selection. So assume I have the following code;
const testvar = '123';
Earlier, if I double clicked on either const Or testvar, it just selected that. However for some reason, it is now selecting both const & testvar
Earlier, if I had my cursor at the start of line and did Ctrl + Right arrow, it would take me to start of next word i.e. testvar. But now, it seems to be hoppinh over 2 words and cursor goes to =
Not sure if some setting got changed unintentionally.

Select all content when Tabulator editor opens

I have a Tabulator (4.9.3) with values that use an editor of type text. As I tab through the table, I want each value to be selected so I can overwrite it without having to clear it first. I have tried putting the usual range selection code into the cellEditing callback and the Tabulator source code where the input gets created. Here is one variation of the code (I can't show them all because the node differs based on context):
try {
if (document.selection) {
// IE
var range = document.body.createTextRange();
range.moveToElementText(input);
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(input);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
} catch (e) {console.log(e);}
If I double-click on the cell, the value selects as desired. How can I get this to work with keyboard navigation as well?
Since the editor is not assigned an id, finding a selector that could find it reliably was problematic without editing the source code. Since I was going to have to edit the source, I ended up adding the following line to the onRendered function of the input element under Edit.prototype.editors.
input.select();

insert GlyphProperty.null in shouldGenerateGlyphs causes cursor misplacement problem

I am hiding the character * by inserting GlyphProperty.null then calling setGlyphs(_:properties:characterIndexes:font:forGlyphRange:) inside layoutManager(_:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:) as described in the answer in https://stackoverflow.com/a/57697139/9568961, it works but after a certain sequence of text editing, the cursor starts to misplace, as shown in the gif https://github.com/dzAtZJU/Demos/blob/master/cursor_misplace.GIF?raw=true
GIF Description: When the second line becomes qq, I try to move the cursor to the end of first line, but it move directly to the beginning. I then try to delete characters, then the cursor move to the end correctly.
The sample project is here https://github.com/dzAtZJU/HideText.
Is it a bug? Have anyone run into this? How can I work around this?
This is a year-old question, but for anyone struggling with the same problem, here's a solution.
My Markdown-like parser knows the ranges for both the line on which the cursor is now, and where it was previously. I'm calling hideAndShowMarkup whenever text view selection changes.
You need to invalidate current glyphs for both of the ranges, and then redraw them synchronously before updating insertion point. The most crucial step is invalidating layout for the range where you want to show Markdown symbols. Without that, your caret gets drawn into the wrong position.
Code is in Objective C, but should be easy to implement in Swift, too.
-(void)hideAndShowMarkup {
// Just for reference
Line* line = currentLine;
Line* prevLine = previouslySelectedLine;
[self.layoutManager invalidateGlyphsForCharacterRange:line.range changeInLength:0 actualCharacterRange:nil];
[self.layoutManager invalidateGlyphsForCharacterRange:prevLine.range changeInLength:0 actualCharacterRange:nil];
[self.layoutManager invalidateLayoutForCharacterRange:line.range actualCharacterRange:nil];
if (NSGraphicsContext.currentContext) {
[self.layoutManager drawGlyphsForGlyphRange:line.range atPoint:self.frame.origin];
[self.layoutManager drawGlyphsForGlyphRange:prevLine.range atPoint:self.frame.origin];
}
[self updateInsertionPointStateAndRestartTimer:NO];
}

Python Selenium, the text of the next element

I can get the text of the first element. But I do not know how to go through the entire list and get the text of each element. Here is the tree from the site:
Screenshot
So I get the text of the first element:
driver.find_element_by_xpath("//a[#my-peer-link='participant.user_id']").click()
print(driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text)
In each
div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in
chatFull.participants.participants"
is contained
div class="md_modal_list_peer_name"
which contains
a class="md_modal_list_peer_name"
my-peer-link="participant.user_id">Олег
which you need to press. That is, execute:
driver.find_element_by_xpath("//a[#my-peer-link='participant.user_id']").click()
After that, a new window opens, from which I get the text of the element:
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
But there are several of these elements and I need to get the text with everyone:
div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in
chatFull.participants.participants"
How to do it?
Vladimir, I haven't done a careful analysis of this problem; however, could it be as simple as this?
Rather than using
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
could you use:
for span in driver.find_elements_by_xpath("//span[#ng-bind=\"'#' + user.username\"]"):
span.text
(Notice plural in `find_elements_by_xpath'.)
You'll need to click each element and store the text in a list:
So first use
elements_to_click = driver.find_elements_by_xpath("//a[#my-peer-link='participant.user_id']"
This will return a list of elements
Loop through those elements by
clicking on element
switch to the new window (When a new WindowHandle was created, otherwise skip this step.)
get the text via
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
store it in a list
close window (When a new WindowHandle is created, otherwise skip this step.)
switch to previous window

Whenever I type colon in insert mode it moves my text to the very beginning of line

Whenever I type a : (colon) it moves all the text on the current line to the beginning of the line, ignoring spaces and tabs.
So if I type
var combo = new Ext.form.ComboBox({
typeAhead //I'm about to type a colon, but right now it looks fine
})
Then I type the colon it moves the text and it now looks like
var combo = new Ext.form.ComboBox({
typeAhead: //text is no longer indented
})
This is a javascript file, so that might be causing the problem?
How can I stop my text from being moved to the beginning of the line when I type a colon?
Adding a colon to the end of a token is causing vim to interpret it as a jump label for C-indenting purposes. :set cino+=L0 should cause it to stay in the current column.
Also, doesn't the JSON syntax allow you to quote the thing that precedes the colon? That should prevent vim from thinking it's a label too.
var combo = new Ext.form.ComboBox({
"typeAhead": "foo" // this isn't a jump label
});

Resources